File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Creating Generic Method ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating Generic Method !" Watch "Creating Generic Method !" New topic

Creating Generic Method !

Prathamesh Gaddam
Ranch Hand

Joined: Feb 18, 2008
Posts: 58

Towards void-return-type generic method why we use preceding <T>, before return type. What does it denotes? Please clarify. I referred K&B however it is not clear to me.
For example:

Thank you in advance!
Charles Lyons
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
It signals to the compiler that your method is in fact a generic method. Otherwise T would not be recognised as a type, but a class name. If you wrote this for example:then the compiler expects that T is a class type for the parameter, not a generic type to be substituted. You'll probably get compiler errors about the class not being found (unless you happen to have a class called T lying around!).

Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
I agree. Here's the link:
subject: Creating Generic Method !
It's not a secret anymore!