The most commonly used type parameter names are:
E – Element (used extensively by the Java Collections Framework)
K – Key
N – Number
T – Type
V – Value
S,U,V etc. – 2nd, 3rd, 4th types
I don’t seem to quite understand what exactly does every letter correspond to. I understand that each letter represents just a convention but what does 2nd, 3rd and 4th type mean exactly? When should I use what? On their official tutorials website it doesn’t give further information.
Some examples:
Map<K, V>: A map usually assignsValues toKeys. These are special kinds of types, so they are used here.List<E>: A list containsElements. It’s a convention that they are called elements. On the other hand,Twould also be acceptable here.Formatter<T>: A formatter can format anyType. It’s not really an element, nor a key, nor a value, soTis the correct letter here.Triplet<T, U, V>: A triplet for arbitrary types. Since the type definition does not know anything about the types that will be filled in later, it uses just theTfor the first type, followed by the next letters in alphabetical order.