Is there a syntax or workaround to constrain a generic type parameter to any of a range of types?
I am aware that you can constrain a type to be all
The following code would do the same thing as in the provided example, but without runtime type checking and typecasts.
public boolean sameAs(MyClass obj) { return this.id.equals(obj.id); } public boolean sameAs(String obj) { return this.id.equals(obj); }
NPE checking might be a good idea.