Semicolon at end of 'if' statement

前端 未结 18 1942
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 01:01

Today, after half an hour of searching for a bug, I discovered that it is possible to put a semicolon after an if statement instead of code, like this:

if(a          


        
18条回答
  •  深忆病人
    2020-11-22 01:21

    A possible use case:

    if (a==b);
    else {
      // Do something
    }
    

    Not good, but possible.

    Still, I do think that the Java specification should disallow an empty if.

提交回复
热议问题