I have below code, where I have a final inner class.
So as per final it should not allow to re-assign it a value. But it still does. Please explain:
public class POJO {
public final String vNew;
public POJO () {
vNew="hello";
}
final class abc {
String name="abc";
}
public static void main(String[] args) {
POJO vPOJO = new POJO();
POJO.abc in=vPOJO.new abc();
System.out.println(in.name);
in.name="World";
System.out.println(in.name);
in=vPOJO.new abc();
System.out.println(in.name);
}
}
Output is
abc
World
abc
The code POJO.abc in=vPOJO.new abc(); and in=vPOJO.new abc(); is re-assignment isn't it.
Just not sure as it uses the handle of outer non final class, makes it work.