2 Replies Latest reply on Dec 3, 2010 11:39 AM by walterln

    Generic method with different parameter types

      Java 6.0 | Generic Methods

      I am trying to implement generics to one of my custom class method, such that it accepts List of custom objects.
      eg: List<MyClassOne> , List<MyClassTwo>

      Generic method :
      public <T> void calcSubTotal(List<T> listObjects, Class<T> type) {

      for(T obj : listObjects) {
      // I want to invoke a method in MyClassOne , MyClassTwo, MyClassThree using the obj reference.
      // All my custom classes have the same method name.



      I am invoking this geenric method like this : calcSubTotal(list , MyClassOne.class );

      calcSubTotal(list , MyClassTwo.class );

      How can I invoke methods / properties in My Custom classes using the generic type parameter ?