繁体   English   中英

为什么 Ballerina 不允许您重新为 function arguments 赋值?

[英]Why doesn't Ballerina let you reassign a value to function arguments?

以下代码片段给出了错误: cannot assign a value to function argument 'a'(BCE2549)

function test(int a) {
    // cannot assign a value to function argument 'a'(BCE2549)
    a = a + 2;
}

这背后的原因是什么,这种行为可以改变吗?

您不能在 Ballerina 中为 function 参数赋值。 这是设计使然。 如果要更新输入参数的值,则必须定义一个新变量,然后对其进行更新。

function test(int a) {
    int b = a + 2;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM