【发布时间】:2019-10-25 17:39:10
【问题描述】:
根据type conversion 示例,使用int.convert() 进行字符串到int 的转换。但是在 Ballerina 1.0.0 中不起作用:
$ ballerina version
Ballerina 1.0.0
Language specification 2019R3
$ cat test.bal
public function main() {
string x = "42";
int|error y = int.convert(x);
}
$ ballerina build test.bal
Compiling source
test.bal
error: .::test.bal:3:19: undefined function 'convert'
$
还有<int> 提到的elsewhere 在SO 中也不起作用:
$ ballerina version
Ballerina 1.0.0
Language specification 2019R3
$ cat test.bal
public function main() {
string x = "42";
int|error y = <int>x;
}
$ ballerina build test.bal
Compiling source
test.bal
error: .::test.bal:3:19: incompatible types: 'string' cannot be cast to 'int'
$
【问题讨论】:
-
你能试试这样的吗:
int val = check <int>strVal;我不是芭蕾舞专家,但我在网上找到了一些东西。尝试在演员表之前使用check。
标签: ballerina