Source of TwoParameterGenericClass.java


  1: //TwoParameterGenericClass.java

  3: //A simple generic class with two type parameters: T1 and T2.
  4: //Note that the two types could be the same, but if that were
  5: //always the case, only one type parameter would be needed.
  6: class TwoParameterGenericClass<T1, T2>
  7: {
  8:     T1 object1;
  9:     T2 object2;

 11:     TwoParameterGenericClass
 12:     (
 13:         T1 o1,
 14:         T2 o2
 15:     )
 16:     {
 17:         object1 = o1;
 18:         object2 = o2;
 19:     }

 21:     //Show types of T1 and T2.
 22:     void showTypes()
 23:     {
 24:         System.out.println("Type of T1 is " + object1.getClass().getName());
 25:         System.out.println("Type of T2 is " + object2.getClass().getName());
 26:     }

 28:     T1 getObject1()
 29:     {
 30:         return object1;
 31:     }

 33:     T2 getObject2()
 34:     {
 35:         return object2;
 36:     }
 37: }