• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023-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
16 /*---
17desc: A rest parameter allows to make a function or method that take an unbounded
18  number of arguments. A rest parameter is marked with ... symbol before parameter
19  name.
20name: spec/rest-params/RestParamsTest_PassInterfaceArgs.ets
21
22---*/
23
24interface Supplier {
25    get(): int;
26}
27
28class SupplierImpl implements Supplier {
29    override get(): int {
30        return 3;
31    }
32}
33
34class Base {
35
36    public call(...values: Supplier[]): int {
37        let sum: int = 0;
38        for(let call of values) {
39            if(call != null) sum += call.get();
40        }
41        return sum;
42    }
43}
44
45class Testee extends Base {
46
47    public call(prefix: String, ...values: Supplier[]): int {
48        let sum: int = 0;
49        for(let call of values) {
50            if(call != null) sum += call.get();
51        }
52        return sum;
53    }
54
55}
56
57function main(): int {
58
59    let test = new Testee();
60    let result: int = 0;
61
62    let si: Supplier = new SupplierImpl();
63    result = test.call("Hello", si, new SupplierImpl(), null as Supplier);
64    if(result != 6) return 1;
65
66    return 0;
67
68}
69