Bounded Types

Contact Us or call 1-877-932-8228
Bounded Types

Bounded Types

A type parameter may set bounds on the type used, by setting an upper limit (in inheritance diagram terms) on the class used. The extends keyword is used to mean that the class must either be an instance of the specified boundary class, or extend it, or, if it is an interface, implement it:

public class EmployeeLocator<T extends Employee> { . . . }
public class CheckPrinter<T extends Payable> { . . . }

In the first case, the class may be parameterized with Employee, or any class that extends Employee. In the second, the class may be parameterized with Payable or any type that implements the Payable interface.

Next