I would like to check how to compare 2 Objects and each Object has nested class within. how can I compare the emp1 and emp2 without the compareTo() inside the Employee class. Do I have to use Reflection?
public class App{
public void addEmployee(){
Person person1 = new Person();
person1.setId(123);
person1.setFirstName("FirstName");
person1.setLastName("LastName");
Employee emp1 = new Employee();
emp1.setPerson(person1);
emp1.setPosition("Tester1");
emp1.setSalary(1000);
Person person2 = new Person();
person2.setId(223);
person2.setFirstName("FirstName2");
person2.setLastName("LastName2");
Employee emp2 = new Employee();
emp2.setPerson(person2);
emp2.setPosition("Tester2");
emp2.setSalary(2000);
//how can I compare the emp1 and emp2 without the compareTo() inside the Employee class.
}
}
public class Person{
private int id;
private String firstName;
private String lastName;
}
public class Employee{
private Person person;
private String position;
private double salary;
}