File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generic Types changin method return types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generic Types changin method return types" Watch "Generic Types changin method return types" New topic

Generic Types changin method return types

Tebogo Maitsapo

Joined: Mar 26, 2010
Posts: 3

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

Joined: Sep 28, 2004
Posts: 20535

Please do a search first next time. This question has come up before...

And welcome to the JavaRanch...


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Tebogo Maitsapo

Joined: Mar 26, 2010
Posts: 3
Thank you Henry. I did not know exately how to search,bt now i do. Thank you
Unmesh Chowdhury
Ranch Hand

Joined: Jun 20, 2010
Posts: 45
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.

M.Sc. in CS, OCPJP6 93%
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3028
Also, did you hear about that new search feature?
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
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.

SCJP 6.0 96%

(Connecting the Dots ....)
I agree. Here's the link:
subject: Generic Types changin method return types
It's not a secret anymore!