public class Test{
ClassB fieldB;
public Test(ClassA instanceA){
fieldB = new ClassB();
fieldB.setOnClickListener(new OnClickListener() {
@Override
public void onClick() {
ClassC.aStaticMethod(_____);
}
});
}
}
I want to use the instanceA object which is passed as parameter to the constructor of ClassA in the blank. How can I do this? Thanks.
Use a final variable/parameter to be able to access it in an anonymous inner class. This is necessary since the anonymous class will make copies of all outer local fields used, and so they must be made final so that their values (usually the reference values) don't change.