Hw To Make Inner Class Distinguish Func Parameter And Outer Class Var
i fail to make an inner class distinguish among function parameter and outer class variable.
consider the following code:
public class a {
int var; // i want to access this one using inner class.
public a(int var) {
this.var = var;
class b {
public void fun() {
var = 100;
}
}
}
}
i get an error a.java:9: local variable var is accessed from within inner class; needs to be declared final.
when i change the code to this:
public class a {
int var; // i want to access this one using inner class.
public a() {
class b {
public void fun() {
var = 100;
}
}
}
}
it compiled no problem.it seems that inner class is accessing function parameter rather than outer class member.
is there any syntax i can use to make me access the outer class member variable whithout renaming or removing the function parameter?
thank you.

