Reputation: 4859
I have a line of code that is essentially this
NameOfAClassOnTheClasspath.
The compiler accepts this without an error or even a warning. I've tried this in eclipse and on the command line.
What on earth can the compiler (javac 1.6) even think this means and why isn't it complaining?
Upvotes: 0
Views: 98
Reputation: 4704
Take into account that the DOT is a binary operator, so it takes a class and a method.
If you wish the ClassLoader to load the class because you do something in the static initialization, then you should consider using Class.forName("YourClass");
Upvotes: 0
Reputation: 23465
Since whitespace is ignored, something like
SomeClass.
staticMethod();
Is a perfectly legal way to call
SomeClass.staticMethod();
(You can replace the method with pretty much any other static member of the class)
e.g. an inner interface of another interface:
Map.
Entry<Integer,Integer> x; // Declares a Map.Entry<Integer,Integer>
Of course it's pretty terrible coding style, unless you're breaking lines that are too long to fit on the screen, and in that case you should indent the rest of the line.
Upvotes: 8