Sorting an array of classes based only on field name
问题 I have an application where a user provides me with the name of a field, e.g name or costInCents , and I have to sort by that field. I have ways of guaranteeing that the field name will be correct. This application causes the complication that I simply cannot make my class Comparable and implement a specific compareTo() , since with a custom implementation of compareTo() I need to know which fields / methods to use at implementation time. So to achieve this goal, I am trying to use reflection