Why do I need to declare a local variable
as final
if my Inner class
defined within the method needs to use it ?
Example :
class MyOuter2 {
private String x = "Outer2";
void doStuff() {
final String y = "Hello World";
final class MyInner {
String z = y;
public void seeOuter() {
System.out.println("Outer x is "+x);
System.out.println("Local variable is "+y);
MyInner mi = new MyInner();
mi.seeOuter();
}
}
}
}
Why the String y
needs to be a final constant ? How does it impact ?