It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes generics 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 "generics" Watch "generics" New topic


Abhishek Bhat

Joined: Jan 01, 2009
Posts: 25

This generics has endless secrets...

Why does it give this error :

non-static class String cannot be referenced from a static context
public static void main(String args[])

Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
No you are using something like this:

Got any idea? Or I need to say some more.

Henry Wong

Joined: Sep 28, 2004
Posts: 20517

Would the error make more sense, if it was written like this?

You have confused the compiler. Your first "String" is actually a type. And your second "String" is the java.lang.String class.

[EDIT: Second to the answer again !! ]


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Abhishek Bhat

Joined: Jan 01, 2009
Posts: 25

Hi Punit,

My attempt to do that was in the line of the <T> concept only...i was testing using all the different Types....the error however was not expected
The rule is ok but the Type conflict is bizzare with the "main" method argument...

Thanks anyway Punit and Henry ... Thanks a lot
I agree. Here's the link:
subject: generics
It's not a secret anymore!