正如Jake King写道,你可以产生一个空的语句,在循环中什么都不做:
while (condition);
但要明确,你会写
while (condition)
;
甚至更好:
while (condition)
/** intentionally empty */
;
甚至更好,正如MichaelKjörling在评论中指出的那样,
while (condition)
{
/** intentionally empty */
}
更多的时候,你会看到它在for-statements中无限循环:
for (;;)
或只有一个空的语句
for (start;;)
for (;cond;)
for (;;end)
另一件可以做的事情就是写一个程序,一次一次,一次用2个分号:
public class Empty
{
public static void main (String args[])
{
System.out.println ("Just semicolons");;
}
}
编译它,并运行列表字节码(标识)的大小,并在字节码(identic)上做一个md5sum.
因此,在语义不变的情况下,它被明确优化,至少对于1.6-Oracle编译器,我可以这么说.