你如何在 Ballerina 中获得变量的类型?
我知道布尔检查是可能的,如下所示:
import ballerina/io;
public function main() {
any x = "This is a test";
io:println(x is string); // Evaluates to true
io:println(x is float); // Evaluates to false
}
Run Code Online (Sandbox Code Playgroud)
在 Python 中,我们使用type(variable)
和获取类型,在 Java 中它如下:
String a = "test";
a.getClass().getName()
Run Code Online (Sandbox Code Playgroud)
我们如何在芭蕾舞女演员中做到这一点?我试图查看文档,我能找到的最接近的是lang.typedesc
.
ldc*_*mal 10
您可以使用typeof expression
for 获取 Ballerina 中任何变量的类型。
import ballerina/io;
public function main() {
var x = 5;
io:println(typeof x);
}
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅下面语言规范的“Typeof 表达式”部分。
https://ballerina.io/spec/lang/2019R3/#section_6.25
归档时间: |
|
查看次数: |
159 次 |
最近记录: |