如何从void更新String对象?
现在它给了我一个错误:无法分配最终的局部变量sObj,因为它是在封闭类型中定义的。
String object = "";
String object2 = "";
String object3 = "";
String object4 = "";
String object5 = "";
digitInput(object); //update string object
digitInput(object4); // update string object4
private void digitInput(final String sObj) {
....
sObj = NEW_VALUE; //With this I want to update passed object
....
}
答案 0 :(得分:2)
您想将object的值设置为sObj的值吗? this.object = sObj;
答案 1 :(得分:1)
从方法签名中删除final
限定符。
答案 2 :(得分:1)
您似乎正在尝试使用该函数重新分配对象的值。你采取的方法很奇怪。我会这样做:
String object = "";
String object2 = "";
String object3 = "";
String object4 = "";
String object5 = "";
object = digitInput(object); //update string object
object4 = digitInput(object4); // update string object4
// assuming you need the original object to generate the new value
private String digitInput(String sObj) {
....
// do something
....
return NEW_VALUE; //With this I want to update passed object
}