If you are wondering what <E>, <K, V>, <N> and so on are called in Java Generics? Well, they are known as "Type Parameters".

Type Parameters are placeholders for data types that are defined when creating generic classes, interfaces, or methods. They are specified inside angle brackets (<>) when defining a generic class, interface, or method.
Examples:
Genetic Interface with Type Parameter E:
interface Payment<E> {
void process(E payment);
}
Genetic Method with Type Parameter E:
public <E> void printElement(E element) {
System.out.println(element);
}
Genetic Class with Type Parameter E:
class Container<E> {
private E item;
public Container(E item) {
this.item = item;
}
public E getItem() {
return item;
}
}
Naming Conventions of Type Parameters:
The Type Parameters are represented by single uppercase letters e.g., E, T, K, V.
| Naming Convention | Type Parameter | Usage | Example |
|---|---|---|---|
E | Element | Used extensively by the Java Collections Framework | List<E> |
K | Key | Typically used in key-value pairs or maps | Map<K, V> |
N | Number | Often used for numeric types | List<Number> |
T | Type | A general-purpose type parameter | Box<T> |
V | Value | Commonly used in key-value pairs or maps | Map<String, V> |
S, U, V, etc. | 2nd, 3rd, 4th types | Used for additional type parameters | Pair<S, T>, Triple<U, V, W> |
This is not an AI-generated article but is demonstrated by a human with Java JDK 21 on a M1 Mac.
Please support independent contributors like Code2care by donating a coffee.
Buy me a coffee!

Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!