Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

declarations with <> operator with classes like S , T , K, V, M, B

 
ulvi ugur
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi all,

Can anybody tell me what the below conventions are called and with which version of Java the are introduced :



or better with a question mark (?)



Thanks in advance,

Ulvi
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generics, Java 1.5
 
ulvi ugur
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Bear,

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 ?

Cheers,

Ulvi
 
Rob Spoor
Sheriff
Pie
Posts: 20555
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the generic type, and it indeed gets replaced with something "real" like Integer, String or whatever you want when you use the class.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

these are called generics and introduced in java 1.5........
hava a look in chapter 7 of kathy book......scjp1.6...if you want to learn it.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally
<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

hope it clear the generic terminology.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49466
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look in the Java™ Tutorials: here, and here.
 
ulvi ugur
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks guys, very helpful !
 
Campbell Ritchie
Sheriff
Pie
Posts: 49466
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Campbell Ritchie
Sheriff
Pie
Posts: 49466
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatasamy wrote:Generally
<T,V> or <T> is called as type parameter.
Isn't that (<T>) called a formal type parameter, and when you write List<String>, then "String" is the actual type parameter? I think that's correct, but I'm not sure.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the exact definition:

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).
 
Campbell Ritchie
Sheriff
Pie
Posts: 49466
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic