Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why hyperlink in Java source code does not produce compile error? [duplicate]

Tags:

java

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...

like image 633
Maris B. Avatar asked Sep 11 '26 16:09

Maris B.


2 Answers

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.

like image 50
3 revs, 2 users 94%T.J. Crowder Avatar answered Sep 13 '26 06:09

3 revs, 2 users 94%T.J. Crowder


Because :

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

http: is a label and the rest is a comment

like image 26
YCF_L Avatar answered Sep 13 '26 06:09

YCF_L



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!