This cannot be achieved; you cannot create an instance of an object that has already been created:
private void myMethod(){
final Object object = null;
object = new Object();
}
Eclipse gives an error message:
The destination local object cannot be assigned to a variable. It must be empty and not use a composite assignment.
However, if you pass this object to another method:
private void _myMethod(Object object){
object = new Object();
}
It can be achieved!
final form:
private void myMethod(){
final Object object = null;
_myMethod(object);
}
private void _myMethod(Object object){
object = new Object();
}
Can someone explain this to me? This is so confusing how Java works.
source
share