Why does it happen?
Java Language Specification says that:
The Empty Statement
An empty statement does nothing.
EmptyStatement: ;
Execution of an empty statement always completes normally
It essentially means that you want to execute empty statement if a==b
if(a == b);
What should you do:
There are two main solutions to this problem:
-
You can avoid problems with empty statement by using code formatter
and surrounding stuff insideif
with{
and}
. By doing this
Your empty statement will be much more readable.if(a == b){ ; }
-
You can also check tools used for static code analysis such as:
They can instantly highlight problems such as this one.
I would recommend to combine both solutions.