为什么连续分号的代码会编译? [英] Why does code with successive semi-colons compile?
问题描述
根据我的科学Java实验, 正如Jake King所写,你可以制作空的陈述,什么都不做循环中: 但要明白,你会写 甚至更好: 甚至更好,正如MichaelKjörling在评论中指出的那样, 更常见的是,你会在无限循环的for语句中看到它: 或只有一个空语句 你可以做的另一件事是,编写一个程序,一个用一个,一个用2个分号: 编译它,并运行list字节代码的大小(identic)并在字节码上执行md5sum(identic)。 因此,在没有改变语义的情况下,它显然已经被优化了,至少对于1.6-Oracle编译器我可以这么说。 According to my scientific Java experimentation,
As Jake King writes, you can produce empty statements to do nothing in a loop: but to make it obvious, you would write or even better: or even better, as Michael Kjörling pointed out in the comment, More often, you see it in for-statements for endless loops: or only one empty statement Another thing you can do, is, to write a program, once with one, and once with 2 semicolons: Compile it, and run list the size of byte code (identic) and do an md5sum on the bytecode (identic). So in cases, where the semantics aren't changed, it is clearly optimized away, at least for the 1.6-Oracle compiler I can say so. 这篇关于为什么连续分号的代码会编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! int x = 0;
相当于 int x = 0 ;;
相当于 int x = 0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >
while(condition);
while(condition)
;
while(条件)
/ **故意为空* /
;
while(条件)
{
/ **故意空* /
}
for(;;)
for(start ;;)
for(; cond;)
for(;; end)
公共类空
{
public static void main(String args [])
{
System.out.println(Just semicolons);;
}
}
int x = 0;
is equivalent to int x = 0;;
which is equivalent to int x = 0;;;;;;;;;;;;;;;
while (condition);
while (condition)
;
while (condition)
/** intentionally empty */
;
while (condition)
{
/** intentionally empty */
}
for (;;)
for (start;;)
for (;cond;)
for (;;end)
public class Empty
{
public static void main (String args[])
{
System.out.println ("Just semicolons");;
}
}