0

I am reading java concurrency in practice. I read one segment which is as follows :

public class ThisEscape {
  public ThisEscape (EventSource source) {
     source.registerListener(
        new EventListener () {
           public void onEvent (Event e){
              doSomething(e);
           }
        }); 
  }
}
When the inner event listener instance is published, so is the enclosing ThisEscape instance

Can anyone please help me understand what this exactly means? I am unable to understand this concept.

Page 28
listing 3.7 diagram
section 3.2.1
Amit Gupta
  • 107
  • 2
  • 10
  • 1
    @BasilBourque just fixed the minor typo and added the book reference – Amit Gupta Jan 28 '22 at 17:10
  • 1
    While this is true for now, it may change if you [compile it with Java 18](https://bugs.openjdk.java.net/browse/JDK-8277604) - if `doSomething` is static and `EventListener` is not serializable. – Johannes Kuhn Jan 28 '22 at 17:22
  • @JohannesKuhn but could you please explain me what is the problem with above snippet. How is the reference escaping in above code ? – Amit Gupta Jan 28 '22 at 17:25
  • 1
    FYI, in MarkDown, use a greater-than (“>”) for quotations. The triple-backtick is for code, not quotes. – Basil Bourque Jan 28 '22 at 18:46

0 Answers0