gpt4 book ai didi

java - 为什么编译器没有出现错误?

转载 作者:行者123 更新时间:2023-12-02 00:37:01 24 4
gpt4 key购买 nike

我刚刚发现我的编译器允许我编写下面的代码并且没有引发任何编译时错误。有谁可以赐教一下吗!

double y = arcToFindPointOn.getCenterXY().y - arcToFindPointOn.getRadius()*Math.sin(theta);;

上面代码行的奇怪之处在于最后的分号!

谢谢!

最佳答案

在其他语言中,例如 C# 和 C++,只有 ; 的指令意味着空指令,并且是允许的,不会生成任何错误,并且不会执行任何操作。

网上有很多这方面的文章,找到了这篇:Multiple semicolons are allowed by the C# Compiler for statement termination

This is a little weirdness inherited from C. In fact your example isn't a statement terminated by three semicolons, but three statements, two of which are empty. Occassionally it can be useful to use the empty statement in e.g. an if statement or a while loop, and then it would seem arbitrary to disallow it elsewhere. Besides, changing it now would be an unnecessary breaking change.

关于java - 为什么编译器没有出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7545375/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com