{ io:println("string"); } any k => { i-6ren">
gpt4 book ai didi

ballerina - 芭蕾舞女 Actor 中的 `any` 和 `var` 有什么区别

转载 作者:行者123 更新时间:2023-12-03 04:02:31 25 4
gpt4 key购买 nike

我正在努力

var myVar = "my var";

match myVar {
string s => { io:println("string"); }
any k => { io:println("any var"); }
}

这似乎是不正确的。 varany 之间有什么区别。我想当我在 ballerina 下使用 var 时会创建一个 any 吗?正确吗?

最佳答案

“any”是表示 Ballerina 程序可以操作的所有值的类型。

any myVal = "this is a string value";

// Unsafe type cast, hence the union type.
string | error myStr = <string> myVal;

// Following is also valid based on the definition of the "any" type.
any myVal = 10;

“var”是一种声明变量的方法,该变量的类型是从右侧表达式推断出来的。一旦派生了变量的类型,您就只能分配该类型的值。

// This is equivalent to 'string a = "this is a string value";'
var a = "this is a string value";

// Now the following will result in a compilation failure.
a = 10;

关于ballerina - 芭蕾舞女 Actor 中的 `any` 和 `var` 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50283505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com