public class ThisEscape {
public ThisEscape(EventSource source) {
} }
source.registerListener(
new EventListener() {
public void onEvent(Event e) {
doSomething(e);
} });
As per my understandingpublic class SafeListener {
private final EventListener listener;
private SafeListener() {
listener = new EventListener() {
public void onEvent(Event e) {
doSomething(e);
} };
}
public static SafeListener newInstance(EventSource source) {
SafeListener safe = new SafeListener();
source.registerListener(safe.listener);
return safe;
} }
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.
TRUSTED BY
ASKER
2) And in first case even though this object escapes to the listener when in a non completed state.
Still its the object pointer and when the object will be created it will be pointing to the correct one only.
I am thinking that the point of this example was to avoid escaping of this.
But this is getting escaped in both the cases anyway