• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics

 
Suddhasattwa Mukherjee
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

what this code is signifying?Particularly the line
 
Ben Smither
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought they were supposed to be same - the class type and return type...
 
Ken Truitt
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic