anonymous-inner-class

keyword for the outer class from an anonymous inner class?

In the following snippet public class a{ public void otherMethod(){} public void doStuff(String str, InnerClass b){} pubic void method(a){ doStuff("asd", new InnerClass(){ public void innerMethod(){ otherMethod(); } } ); } } Ss there a keyword to refer to the outer class from the inne...

How do you resolve a circular dependency with an inner class?

(Java question) If I reference a field in an inner class, does this cause a circular dependency between the enclosing class and the inner class? How can I avoid this? Here is an example: public class Outer { private Other o; private Inner i; public Outer() { o = new Other(); i = new Inner() { public void d...

Accessing an outer anonymous class's field from an inner anonymous class

To access the field x of an outer class A from an inner class B, I realize that you can use "A.this.x". But what if the outer class is also anonymous? For example, public class Main1 { public static void main(String[] args) { Comparable c1 = new Comparable(){ int x = 3; public int compareTo(Object o)...

What is this type of method overriding called in Java?

I'm relatively new to Java and I'm using a new API. I came across this method override and I'm not sure what this is called: public void exampleMethod() { Button loginButton = new Button("login"){ public void onSubmit(){ //submit code here } }; } From what I understand, this is overriding the onSubmit m...

Anonymous Inner Classes Inside Methods

Please have a look at following code : import java.util.ArrayList; import java.util.List; class Main{ public static <T> List<T> modifiedList(final List<T> list){ return new ArrayList<T>(){ @Override public boolean add(T element){ super.add(element); return list.ad...

how to reference a higher class within an anonymous class

I have this code: public class Home extends Activity{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... //at some point I have s.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){ @Override public ...

Is there a syntax to get the reference to an anonymous inner class from a further anonymous inner class?

Consider this case: public class SomeClass { public void someMethod() { new SomeInterface() { public void someOtherMethod() { new SomeOtherInterface() { new someThirdMethod() { //My question is about code located here. }...