Is it possible to do something like this (I use initializer blocks to shorten the example)
new A() {{
new B() {{
method(outer.this);
}}
}}
Where I supply the this of the outer object as a parameter to the method call within the second anonymous class? I cannot use A.this, this gives a compile error.
Note: the given code does not compile, it should only illustrate what I'm trying to achieve.
Edit: example that lies closer to the actual use case:
public class Outer {
public SomeBean createBean() {
return new SomeBean() {
private final Object reference = new SomeClass() {
@Override
public void notify() {
Outer.callback(/*what goes here???*/);
}
};
//Methods...
};
}
public static void callback(final SomeBean bean) {
// do stuff with bean
}
}
And the compile error I get is just that I'm not providing the correct argument to callback, as I don't know how to reference the SomeBean subclass...
this. Also, can you please show us the compiler error?