I have a Person object that has been initialized and if I call the method like getName I can retrieve them.
public Person( String fName, String lName, List<Role> roleList) {
this.firstName = fName;
this.lastName = lName;
this.roleList = new ArrayList<Role>();
}
Each Person needs to have a list of roles so I have a list called roleList
which I initialize using List<Role> roleList = new ArrayList();
when created it is passed as
testDriver = new Person("Mike", "Joy", testRoleList);
testDriver2 = new Person("Rich", "Johns", testRoleList);
In my calling class i want to add an item only to that staff members testRoleList
. For this test i have made testRoleList
public but I do have a getter which retrieves the testRoleList
;
Role roleToAdd = Role.DRIVER;
// Only add the new role to the test driver
testDriver.testRoleList.add(roleToAdd);
But when you run this it does add the role, but if I try to retrieve the size of the testDriver and testDriver2 list using:
System.out.println(testDriver.testRoleList.size());
System.out.println(testDriver2.testRoleList.size());
The resulting list size is 1 for both list even though I haven't added a role to the testDriver2.
How can I just add the role to just testDriver or Just testDriver2