Last active
August 29, 2015 14:25
-
-
Save Maslor/19853de3d7e18f17dfb2 to your computer and use it in GitHub Desktop.
Getting a subclass element from the abstract superclass type list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private List<Manager> _managers = new ArrayList<Manager>(); | |
private List<Employee> _employees = new ArrayList<Employee>(); | |
private List<User> _usrs = new ArrayList<User>(); | |
public User findUser(String userID){ | |
refreshUserList(); //updates _usrs so it has all the current users | |
Iterator<User> i; | |
User u = null; //abstract class User | |
i = this._usrs.iterator(); | |
while(i.hasNext()) { | |
u = i.next(); | |
if(u.getID().equals(userID)){ | |
if(u.getRole().equals("employee")) { | |
u = (Employee) u; //Employee extends User | |
break; | |
} | |
u = (Manager) u; //Manager extends User | |
} | |
} | |
return u; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment