The question is not about concurrency.
I'm reading B. Goetz's Java Concurrency in practice and now I'm at the section 3.2
about object publication. He said
A final mechanism by which an object or its internal state can be published is to publish an inner class instance, as shown in ThisEscape in Listing 3.7.
public class ThisEscape {
public ThisEscape(EventSource source) {
source.registerListener(
new EventListener() {
public void onEvent(Event e) {
doSomething(e);
}
});
}
}
}
So, I tried to write my own harmful example of such publication. Here it is:
public class InnerPublication {
public static void main(final String[] args){
Subscriber s = new Subscriber();
s.subscribe(new ToPublish(){ });
}
public abstract static class ToPublish{ }
public static class Subscriber{
public void subscribe(ToPublish tp){
//How can I use the published enclosing instance to do some harm?
}
}
}
Since, anonymous class is always (even in a static context) an inner class, we've got a publication here. But I don't see how I could use the publication to do some harm on the enclosing instance.