Consider the problem: someone needs to implement, say, java.util.Set< E > interface with his/her own class. The .add(E e)
method explicitly declared to expect the object of the type denoted with the generic parameter E. However, the .remove(Objec o)
method explicitly declare to accept any object.
Thinking the static typing way, one might be embarassed with such thing. He/She still needs to back up E-type objects only.
Is there an elegant way to check for the object o, given as a parameter for the remove method, to be an instance of the generic type E?