0

Java – 3 ways to implement a Generic Interface

A Generic Interface is an interface that makes use of Formal Type Parameters.  It uses Generics. There are 3 ways to implement a Generic Interface.

A Generic Interface

A Generic Interface looks something like this:

Implementing Generic Interface

1. Ignore the Formal Type Parameters altogether

Nowadays, this is a bad practice. Old (or legacy) codes written in pre-JDK1.5 are like these codes.

A warning is also generated and displayed in your IDE.

2. Create a Generic Class

Another way is to create a Generic Class that implements the Generic Interface.

3. Create a class that deal with specific non-generic types

Notice we specified a type Elephant for this class instead of another Formal Type Parameter.

References

Karl San Gabriel

Karl San Gabriel

Java and Enterprise Technologies Expert