• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Generics, Java 1.5
 
ulvi ugur
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79255
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks guys, very helpful !
 
Campbell Ritchie
Marshal
Posts: 79255
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
Campbell Ritchie
Marshal
Posts: 79255
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79255
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic