This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics" Watch "Generics" New topic
Author

Generics

Suddhasattwa Mukherjee
Ranch Hand

Joined: May 28, 2008
Posts: 52

what this code is signifying?Particularly the line
Ben Smither
Greenhorn

Joined: Sep 09, 2008
Posts: 4
The type of the fn() can be different than the type of Class. So if you have Class <String>, you can return an Integer in fn().

Originally posted by Suddhasattwa Mukherjee:

what this code is signifying?Particularly the line
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
I thought they were supposed to be same - the class type and return type...


The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Ken Truitt
Ranch Hand

Joined: Aug 23, 2007
Posts: 124
Looks to me like a generic class (signified by the <T> after the class
name, which is Class, although the class keyword is omitted) with a
generic method.

The generic method is using the same identifier as the
class so I would guess that it means that the method will be using the
same type as the class itself.

So in the method, the method type is <T>, but the return type is T.

so somewhere if someone had new Class<String>(), all those T's would
be String. Either that, or I'm wrong.


SCJP 88% | SCWCD 84%
 
 
subject: Generics