Let's first look at the interface design.
public interface Comparable<T> { public int compareTo(T o); }
This is pretty typical, we have to say. Therefore, if our class must implement it, we do this.
pubilc class ICanComparteWithMyself implements Comparable<ICanComparteWithMyself> { public int compareTo(ICanComparteWithMyselfo)
As we see the general type of parameter, we determine what we will work on, so for generics we act the same way
public class ICanCompareMyGeneric<T> implements Comparable<T> { public int compareTo(T o)
In your case, whawt, we want it to ensure that common parameters are implemented, is proprietary Comparable, for this we need to do this
public class MyGenericCanCompareToItself<T extends Comparable<T>> { }
As we can see, this is often used. The expected limitation (or not) is that we can work on classes that implement Comparable for it of type self. If we had
public class ICanCompareStrings implements Comparable<String> { public int compareTo(String o)
So, for the class MyGenericCanCompareToItself as a general parameter, we can use the class public MyGenericCanCompareToItself , but not ICanCompareStrings .
EDIT:
So, when we covered the basics, we can solve your problem
The description of your class is as follows:
public class Pair<T1 extends Comparable<? extends Object>, T2 extends Comparable<? extends Object>>
This is not a big deal, as it is less than <?>
This description says:
I am a Pair class that works with two universal parameters that can use comparison compared to what I don't know.
With this code, you cannot progress until the general parameters are aware of it, and then operate there so that you end up with something like this.
first.getKey.compareTo(null);
And that's why the code does not compile when you try to cast, the expected type is null.
To change what you need to determine what type of your general options should be comparable.
For example, you can compare on your sheet
public class Pair<T1 extends Comparable<T1>, T2 extends Comparable<T2>>
This description says:
I am a Pair class that works with two parameters, each of which can be compared with itself.
And this is what you are probably looking for, besides, they can be compared with something that could be a superclass T1 or T2
public class Pair<T1 extends Comparable<? super T1>, T2 extends Comparable<? super T2>>
This description says:
I am a Pair class that works with two parameters, each of which can be compared with the classes that deliver them.
I hope this helps you with generics; -).