Is there a goto statement in Java?

2018-12-31 08:13发布

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?

23条回答
流年柔荑漫光年
2楼-- · 2018-12-31 08:28

No, thankfully, there isn't goto in Java.

The goto keyword is only reserved, but not used (the same goes for const).

查看更多
呛了眼睛熬了心
3楼-- · 2018-12-31 08:28

http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.goto

If you have been told that there is no goto statement in Java you have been fooled. Indeed, Java consists two layers of 'source' code.

查看更多
荒废的爱情
4楼-- · 2018-12-31 08:31

To prevent people from being killed by velociraptors.

查看更多
爱死公子算了
5楼-- · 2018-12-31 08:32

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html

"The keywords const and goto are reserved, even though they are not currently used. "

查看更多
不再属于我。
6楼-- · 2018-12-31 08:32

goto is not in Java

you have to use GOTO But it don't work correctly.in key java word it is not used. http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html

   public static void main(String[] args) {            
            GOTO me;
            //code;
            me:
            //code; 
            }   
   }
查看更多
呛了眼睛熬了心
7楼-- · 2018-12-31 08:33

No, goto is not used in Java, despite being a reserved word. The same is true for const. Both of these are used in C++, which is probably the reason why they're reserved; the intention was probably to avoid confusing C++ programmers migrating to Java, and perhaps also to keep the option of using them in later revisions of Java.

查看更多
登录 后发表回答