android - Java: calling outer class method in anonymous inner class -



android - Java: calling outer class method in anonymous inner class -

recently, ran mysterious problem in android project, described here. somehow solved problem, still don't know exact reason behind it.

let's want phone call function foo() in inner class. question is, what's difference between calling straight like

foo();

or calling outer class instance

outerclass.this.foo();

besides, appreciate if can check lastly question related this, , give me clue why error occurs. many thanks.

ps: read somewhere non-static inner class hold instance of outer class. phone call outer function using instance if utilize foo()?

the latter more explicit , allow phone call outer class method if 1 exists in inner class same name.

class outerclass { void foo() { system.out.println("outer foo"); } view.onclicklistener mlistener1 = new view.onclicklistener() { void foo() { system.out.println("inner foo"); } @override public void onclick(view view) { foo(); //calls inner foo outerclass.this.foo(); //calls outer foo } } view.onclicklistener mlistener2 = new view.onclicklistener() { @override public void onclick(view view) { foo(); //calls outer foo outerclass.this.foo(); //calls outer foo } } }

java android inner-classes

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -