This can't be achieved, you cannot instantiate an already instantiated final object:
private void myMethod(){
final Object object = null;
object = new Object();
}
Eclipse gives you an error message:
The final local variable object cannot be assigned. It must be blank and not using a compound assignment
However, if you pass this object to another method:
private void _myMethod(Object object){
object = new Object();
}
This can be achieved!
final form:
private void myMethod(){
final Object object = null;
_myMethod(object);
}
private void _myMethod(Object object){
object = new Object();
}
Could anyone explain me this? It is so confusing how Java works.