Generic Interfaces
Generics can also be used with interfaces. Generic interfaces are specified similar to generic classes.
Syntax for creating and implementing generic interfaces:
interface interface-name <type-param-list>
{
//…
}
class class-name<type-param-list> implements interface-name<type-arg-list>
{
//…
}
The generic interface offers two benefits.
-
First, it can be implemented for different types of data.
-
Second, it allows users to put constraints (that is, bounds) on the types of data for which the interface can be implemented.