• 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

Generic Types changin method return types

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Source




How come suddenly the get() method returns an integer? Please be detailed in your answer as i would like to derive a rule from it. Or simply jst provide me with a rule/s around this problem. My first topic from south africa. Thank you
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please do a search first next time. This question has come up before...

https://coderanch.com/t/497555/java-programmer-SCJP/certification/Generics-Class-Type-Parameter


And welcome to the JavaRanch...

Henry
 
Tebogo Maitsapo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Henry. I did not know exately how to search,bt now i do. Thank you
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, in your Test class String is not java.lang.String, it is the type parameter of generic class Test<String> which will be substituted by the actual type, and in your case, the actual type is java.lang.Integer. More generally, we can say type parameter is the placeholder of the actual type and we can declare any legal identifier as type parameter.
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, did you hear about that new search feature?
 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Type- parameters could be Class names too for creating confusions. It is always better to think it as a T or E or anything you feel comfortable with, but ultimately it has to act as a placeholder.
reply
    Bookmark Topic Watch Topic
  • New Topic