Printing a list using reflection
- by TFool
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?