boolean (Object obj) { if (!(obj instanceof MyReference)) return false; //noinspection unchecked MyReference<T> other = (MyReference<T>)obj; T myKey = get(); T otherKey = other.get(); return obj == this || myKey != null && myKey.equals(otherKey); }