First page Back Continue Last page Overview Graphics
Generics
Typed One to Many relationship in Java classes
- public class Team {
private List<Person> members;
private Person teamleader;
}
Allow you to specify element type of collection
- Instead of: List names = new ArrayList();
- Write: List<String> names = new ArrayList<String>();
Enforce specification at compile time (compile time check)
- No casting;
instead of String title = (String) names.get(i);
use: String title = names.get(i);