Java Generics Naming Convention

In this post, we will discuss the Java generics naming conventions with examples.

Read complete Java naming conventions at https://www.javaguides.net/2018/08/java-standard-naming-conventions.html.

Generic types naming conventions

Generic type parameter names should be uppercase single letters. The letter 'T' for a type is typically recommended. In JDK classes, E is used for collection elements, S is used for service loaders, and K and V are used for map keys and values.
public interface Map <K,V> {}
 
public interface List<E> extends Collection<E> {}
 
Iterator<E> iterator() {}
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

Reference

Comments