Wednesday, August 27, 2008

Yet another Java Puzzle

No words here, just the code :)

class String
{
public static void main(String args[])
{
String String = new String();
}
}

5 comments:

Dimitri said...

I think there is a typo:

String String
should be
String string

Stas Ostapenko said...

Dimitri, it's the part of story :) Try to compile the code.

nav said...

We can do similar thing like : Vector Vector = new Vector
because rules for declaring java identifiers (methods, variables, class names etc) permit it. See Java Specification.

Stas Ostapenko said...

Nav, yes, I know. As for me, it looks interesting...

Alex Boyd said...

Ah, tricky. Compiles fine, but fails to run, because its main method takes an array of that String class itself, not java.lang.String... I totally missed that. I was thinking it would fail to compile, and now I'm not sure why I thought that...