Passing Object type and Field to Comparator
问题 Is it possible to write a Comparator so that I can pass the Object type, the field type and the field I like to sort on? I've made some small changes to http://www.davekoelle.com/files/AlphanumComparator.java to accommodate sorting on the field email of type String in the Object type User . I have this code that works. public class Main { public static void main(String[] args) { List<User> users = new ArrayList<>(); users.add(new User(7, "user1", "user1@c.com")); users.add(new User(11,