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.

[992 byte] By [KwangHooi] at [2007-9-30 15:01:03]
# 1
Hi,Yes there is:a.this.var = 100; //Use this in the inner class./Kaj
kajbj at 2007-7-5 21:33:51 > top of Java-index,Archived Forums,Java Programming...
# 2
Do you have to declare class b in the constructor of a? If you put it outside it works.
UlrikaJ at 2007-7-5 21:33:51 > top of Java-index,Archived Forums,Java Programming...
# 3
> a.this.var = 100; //Use this in the inner class.Amazing syntax -:)
UlrikaJ at 2007-7-5 21:33:51 > top of Java-index,Archived Forums,Java Programming...