package generics; import java.util.*; /** A generic method that can return the maximal of two values that are of the same type. */ public class GenericMethod { static > T max(T x, T y){ return (x.compareTo(y) < 0 )?y:x; } public static void main(String[] args){ Mammal d1=new Dog(); d1.setName("Pluto"); d1.setAge(2); Mammal d2=new Dog(); d2.setAge(1); d2.setName("Smart"); System.out.println(max(new Integer(21),new Integer(12))); System.out.println(max("s1","s2")); System.out.println(max(d1, d2).toString()); } }