Interviewer question in one of my interviews.
We have
Employee
class withid
,firstName
, andlastName
fields and getters and setters of these fields. We do not have source code of this class, it is in JAR. We are usingEmployee
instances as the key inTreeMap
. Now we want to sort thisTreeMap
based on theEmployee
id
field.
I know we can use Comparable
interface to sort but how can we use it if we do not have the source code?