Without changing the signature you can do
void foo(Object first, Object second){ if (!first.getClass().isInstance(second)) return; Comparable<Object> firstComparable = (Comparable<Object>)first; Comparable<Object> secondComparable = (Comparable<Object>)second; int diff = firstComparable.compareTo(secondComparable); }
But you still have:
Type safety: Unchecked cast from Object to Comparable<Object>
but not Comparable is a raw type. References to generic type Comparable<T> should be parameterized Comparable is a raw type. References to generic type Comparable<T> should be parameterized
and no Type safety: The method compareTo(Object) belongs to the raw type Comparable. References to generic type Comparable<T> should be parameterized Type safety: The method compareTo(Object) belongs to the raw type Comparable. References to generic type Comparable<T> should be parameterized
oliholz
source share