Why there is no error raised by compiler?
I just found my compiler allowed me to write below code and did not raised any compile time error. Could anyone please enlighten me!
double y = 开发者_JAVA技巧arcToFindPointOn.getCenterXY().y - arcToFindPointOn.getRadius()*Math.sin(theta);;
Weird thing about above code line is semi-colon at the very end!
Thanks!
in other languages as well, like C# and C++, having an instruction with only ;
means empty instruction and is allowed, generates no errors and simply does nothing.
plenty of articles on this online, found this one: 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 also allows for the empty statement:
;
which actually does nothing at all. In your example you just have one at the very end.
The ";" is a delimiter, so the compiler can safely ignore the blank statement. However some IDEs help you optimize code and will not let you get away with this statement.
精彩评论