2

In the source code I forgot to add comment before the link. For example, the following code:

public class HelloWorld
{
  public static void main(String[] args)
  {
    http://www.example.com/random-link-here
    System.out.println("Hello World!");
  }
}

Why it compiles? Somehow unable to figure out what it does... Its like label for Goto + comment, but Java does not have a goto...

Maris B.
  • 2,333
  • 3
  • 21
  • 35

3 Answers3

6

The http: part is a label labelling the statement that follows. The // part introduces a line comment.

Normally you see labelled statements in directed break situations, like:

outer:
for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
         if (someConditionThatNeedsToTakeUsOutOfBothLoops) {
             break outer;
         }
    }
}

...however any statement may have a label. In your case you've labelled the System.out.println("Hello World!"); statement.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
5

Because :

http:   //www.example.com/random-link-here
^^^^    ^--------------------------------^

http: is a label and the rest is a comment

Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
1

This is a famous Java Puzzler. It is a label for a goto with a comment. Java reserves the goto keyword, but does not actually implement the goto statement. Look at Puzzler 22 from http://www.javapuzzlers.com/ as a related example.