This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am actually using generics for collections to declare the content of it but what do these single letters mean ? Are they real classes or is it just a dummy identifier to be replaced with a real class ?
<T,V> or <T> is called as type parameter.
<?> is called as unbounded wildcard notation
bounded wildcard :
<? extends Class> is called as upper bounded wildcard notation
<? super Class> is called as lower bounded wildcard notation
The single letters are the type parameters of the generic class that they are specified in. Note that they don't have to be single letters; using single, upper-case letters for type parameters is just convention.
Section 4.4 of the Java Language Specification describes type variables. You can use type variables in generic class, interface, method and constructor declarations as parameters in those declarations - so there they are called type parameters.
When you use a generic class or interface with a specific type, in other words when you fill in specific, existing types for the type arguments, you get a parameterized type. For example, List<String> is a parameterized type - you've filled in String for the type parameter T of the generic type List<T>. The Java Language Specification calls the type that you fill the parameter with the actual type argument.
The words "parameter" and "argument" mean the same (so "type parameter" and "type argument" also mean the same).
Joined: Oct 13, 2005
Thank you, Jesper. I suspect I got my nomenclature from Effetive Java by Bloch, and Bloch uses a different nomenclature from the Java Language Specification.