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

Generic Types changin method return types

 
Tebogo Maitsapo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
 
Henry Wong
author
Marshal
Pie
Posts: 21193
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do a search first next time. This question has come up before...

http://www.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
  • Quote
  • Report post to moderator
Thank you Henry. I did not know exately how to search,bt now i do. Thank you
 
Unmesh Chowdhury
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • 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.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, did you hear about that new search feature?
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic