Comparable
is an interface which contains the method compareTo()
.
In the code that uses a generic method to return the largest of three comparable objects, compareTo()
method is used directly without implementation. How is that possible? Is it because we are"extending" that interface in the class and not "implementing" it?
public class Max {
public static <T extends Comparable <T>> T maximum(T x, T y, T z) {
T max=x;
if (y.compareTo(max) > 0)
max=y;
if (z.compareTo(max) > 0)
max=z;
return max;
}
}