• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static Generic types

 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is the following not allowed



Can i see an example as to why this is not a good idea.

Thanks



 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider


Now what is the type of Gen.foo?
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler error is -
Cannot make a static reference to the non-static type T


Regards,
Dan
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok got that. What about when the type parameter is on the method:



The above is allowed. Does this not cause the same issue? i.e. what type will foo() return?
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will return whatever type is specified (or inferred) on the method call.
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you provide an example of how that method would be used. (I dont really get it).

Thanks
 
Tomasz Sochanski
Ranch Hand
Posts: 47
Eclipse IDE Java Oracle
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic