A colleague came across some code that looked like this and couldn't understand how it could ever compile:
class FooClass {
public static void bar(String arg) {
System.out.println("arg = " + arg);
http://www.google.com
System.out.println("Done!");
}
}
Basically, there was a random URL pasted in the middle of a method but javac
didn't care.
We worked out so I'll post the answer if no-one else finds out but I thought it was interesting enough to post.
"http:" is interpreted as a label. What follows is an end-of-line comment.
Easy. The highlighting on this site shows why.
http: is a label, as in break http;
//www.google.com is a comment.
http: is the label. // starts the comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With