I'm confused about this. Most of us have been told that there isn't any goto statement in Java.
But I found that it is one of the keywords in Java. Where can it be used? If it can not be used, then why was it included in Java as a keyword?
James Gosling created the original JVM with support of goto
statements, but then he removed this feature as needless. The main reason goto
is unnecessary is that usually it can be replaced with more readable statements (like break/continue
) or by extracting a piece of code into a method.
Source: James Gosling, Q&A session