• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import {I} from "./optionalClassProperty2.ets"
17
18// 1. multiple classes implements single interface
19interface I1 {
20    a ?: Array<number>
21}
22class C11 implements I1 {
23    a ?: Array<number>
24}
25class C12 implements I1 {
26    a ?: Array<number>
27}
28
29// 2. multiple classes implements multiple interfaces
30interface I21 {
31    a ?: Array<number>
32}
33interface I22 {
34    b ?: Array<number>
35}
36class C21 implements I21, I22 {
37    a ?: Array<number>
38    b ?: Array<number>
39}
40class C22 implements I21, I22 {
41    a ?: Array<number>
42    b ?: Array<number>
43}
44
45// 3. add readonly attr for interface property
46interface I3 {
47    readonly a ?: Array<number>
48    readonly b ?: Array<number>
49}
50class C3 implements I3 {
51    readonly a ?: Array<number>
52    b ?: Array<number>
53}
54
55// 4. add private qualifier for interface property
56interface I4 {
57    private a ?: Array<number>
58}
59class C4 implements I4 {
60    a ?: Array<number>
61}
62
63// 5. class has owner property which is not included by interface
64interface I5 {
65    a ?: Array<number>
66}
67class C5 implements I5 {
68    a ?: Array<number>
69    b : string = ""
70    c ?: int
71}
72
73// 6. Getter or Setter instead of field
74interface I6 {
75    get a() : Array<number> | undefined
76    set a(arr : Array<number> | undefined)
77}
78class C6 implements I6 {
79    a ?: Array<number>
80}
81
82// 7. super interface
83interface I71 {
84    a ?: Array<number>
85}
86interface I72 extends I71 {
87    b ?: Array<number>
88}
89class C7 implements I72 {
90    a ?: Array<number>
91    b ?: Array<number>
92}
93
94// 8. cross script file
95class C8 implements I {
96    a ?: Array<number>
97}
98