The disadvantages of shell classes are few. One caveat is that wrapper classes are not suitable for use in callback infrastructures, where objects pass their own references to other objects for subsequent calls (βcallbacksβ). Since the wrapped object does not know about its shell, it passes a reference to itself (this), and callbacks elude the shell.
Can someone explain what this means, for example, with an example. It is written in Effective Java, but I did not quite understand it.
To add to the context instead of inheritance, we must approve a composition that leads instead to a subclass of Set , we should use something like this:
public class ForwardingSet<E> implements Set<E> { private final Set<E> s; public ForwardingSet(Set<E> s) { this.s = s; } public void clear() { s.clear(); } public boolean contains(Object o) { return s.contains(o); } ... }
But, as this fails, I am still not able to understand callbacks. In JavaScript, we can use function callbacks, but how the same concept applies to Java, if someone can explain.
source share