• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024-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
16function callbackNoArgVoid(callback: () => void): void {
17    callback();
18}
19
20function callbackNoArgInt(callback: () => int): void {
21    let x: int = callback();
22}
23
24function callbackIntStringBool(callback: (x: int, y: String) => boolean): void {
25    let x: boolean = callback(5, "Hello");
26}
27
28function main(): void {
29    callbackNoArgVoid((): void => {
30        console.println("hello");
31    });
32    callbackNoArgVoid(() => {
33        console.println("hello");
34    });
35
36    callbackNoArgInt((): int => {
37        return new String("hello").length as int;
38    });
39    callbackNoArgInt(() => {
40        return new String("hello").length as int;
41    });
42
43    callbackIntStringBool((x: int, y: String): boolean => {
44        return y.length == x;
45    });
46    callbackIntStringBool((x, y) => {
47        return y.length == x;
48    });
49}
50