• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating Generic Method !

 
Prathamesh Gaddam
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic