一个final
对象不能改变,但我们可以设置其属性:更改最终整型变量的值
final MyClass object = new MyClass();
object.setAttr("something"); //<-- OK
object = someOtherObject; //<-- NOT OK
是否有可能做一个final Integer
相同,改变其int
价值?
我这么问是因为我叫工人:
public SomeClass myFunction(final String val1, final Integer myInt) {
session.doWork(new Work() {
@Override
public void execute(...) {
//Use and change value of myInt here
//Using it requires it to be declared final (same reference)
}
}
,我需要设置它内部的myInt
值。
我可以在另一个类中声明我的int
,并且这可行。但我想知道这是否有必要。
我会用String来代替Number,因为他在他的例子中使用过它:D太挑剔,我知道:D但是很好的简短回答 – sheidaei
AtomicInteger是一个数字。 –
这就是我认为......谢谢:) –