Is there a goto command in Java?

Asked 2 years ago, Updated 2 years ago, 73 views

Is there a goto command in Java? Most people say that Java doesn't have a goto statement.

But I found goto in Java's keyword. What is it used for? If it cannot be used, why is it defined in the Java keyword?

goto java syntax keyword

2022-09-22 11:58

1 Answers

The goto keyword is defined in the Java keyword list. But it's marked "not used."

In this case, it can also be interpreted as meaning that the feature may be added in a later version of Java.

If goto is not defined as a keyword, you can create a variable name called goto and use it as an identifier. However, if goto is defined as a keyword in the next version of Java, all previously used names will be compilation errors due to the rule that identifiers cannot be defined with keywords.

Therefore, those that may be added later are defined as keywords in advance so that the above problem does not occur even if the Java version is updated.


2022-09-22 11:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.