16 lines
524 B
Java
16 lines
524 B
Java
public class GenericMethod8C {
|
|
public static <A extends Comparable <A>> A findMax(A x, A y){
|
|
return x.compareTo(y) > 0 ? x : y;
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
Integer maxInt = findMax(5,10);
|
|
System.out.println("Maximum of 5 and 10 is: " + maxInt);
|
|
|
|
Double maxDouble = findMax(6.7, 9.8);
|
|
System.out.println("Maximum of 6.7 and 9.8 is: " + maxDouble);
|
|
|
|
String maxString = findMax("pineapple", "appleeeeeeeeee");
|
|
System.out.println("Maximum of 'pineapple' and 'apple' is: " + maxString);
|
|
}
|
|
} |