Extending Generic Classes and Implementing Generic Interfaces

Contact Us or call 1-877-932-8228
Extending Generic Classes and Implementing Generic Interfaces

Extending Generic Classes and Implementing Generic Interfaces

When extending a generic class or implementing a generic interface, you can maintain the generic type, as in public class ArrayList<T> implements List<T>. In this case, types are still stated in terms of T.

You can lock in the generic type: public class EmployeeList extends ArrayList<Employee> or public class StringList implements java.util.List<String>. In these cases, methods would use the fixed type. For example, if you overrode add(E) in ArrayList<E> in the above EmployeeList, it would be add(Employee).

Next