aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static Generic types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static Generic types" Watch "Static Generic types" New topic
Author

Static Generic types

O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Why is the following not allowed



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

Thanks



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18674
    
    8

Consider


Now what is the type of Gen.foo?
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
The compiler error is -
Cannot make a static reference to the non-static type T


Regards,
Dan


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

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
Bartender

Joined: Oct 14, 2005
Posts: 18674
    
    8

It will return whatever type is specified (or inferred) on the method call.
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Can you provide an example of how that method would be used. (I dont really get it).

Thanks
Tomasz Sochanski
Ranch Hand

Joined: Jan 13, 2009
Posts: 47

read this thread http://www.coderanch.com/t/562466/java-programmer-SCJP/certification/Genrics-ReturnType
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Thank you all.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Static Generic types