Printing a list using reflection

Posted by TFool on Stack Overflow See other posts from Stack Overflow or by TFool
Published on 2012-06-29T14:19:20Z Indexed on 2012/06/29 15:16 UTC
Read the original article Hit count: 124

Filed under:
|
|
 public class Service{ 
       String serviceName;
      //setter and getter
  }

  public class Version{ 
       String VersionID;
      //setter and getter
  }

  public void test(Object list){

        //it shd print the obtained list

   }

List< Service> list1; //Service is a Bean
List< Version> list2; //Version is a Bean
test(list1);
test(list2);

Now the test method shd print the obtained list - (i.e) If the list is of type Service ,then serviceName should be printed using its getter. If the list type is Version versionID should be printed.
Is it possible to achieve this without using Interface or abstract class?

© Stack Overflow or respective owner

Related posts about java

Related posts about list