I am writing a class to sort objects by name field. I assume work with different types, therefore I use generic
public static <T> List<T> sortStringList(List<T> list, Class type){ List <Integer> numList = new ArrayList(); for (T item : list) { if (item.getClass() == type && type == SubCategory.class) { System.out.println("It subcategory"); } if (item.getClass() == type && type == Category.class) { } } return list; } In the condition I determined with which type I was working, but how now in the list should I change T to the type I need? That is, so that I have for example a list with elements of type Category. I need this in order to access the fields of the Category object.
((Category) list.get(0)).categoryMember? - post_zeew