什么是芭蕾舞女演员中的'any`和`var`之间的区别

nuw*_*ndo 2 ballerina

我想做

var myVar = "my var";

match myVar {
    string s => { io:println("string"); }
    any k => { io:println("any var"); }
}
Run Code Online (Sandbox Code Playgroud)

似乎这不正确.是什么区别varany.我var想当我在芭蕾舞女演员下面使用时会创造一个any?正确?

Sam*_*oma 5

"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;
Run Code Online (Sandbox Code Playgroud)

"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;  
Run Code Online (Sandbox Code Playgroud)