if( 3 % 3 == 0){
return 3;;
}
Java says unreachable statement
.
I understand that java
parses return 3;;
as
return 3;
;
So It says unreachable statement. But it is empty statement. Why does java care about it?
if( 3 % 3 == 0){
return 3;;
}
Java says unreachable statement
.
I understand that java
parses return 3;;
as
return 3;
;
So It says unreachable statement. But it is empty statement. Why does java care about it?
Simple: the Java compiler treats an empty statement as just a statement. As this section from the Java language specification indicates:
Statement:
StatementWithoutTrailingSubstatement
LabeledStatement
IfThenStatement
IfThenElseStatement
WhileStatement
ForStatement
StatementWithoutTrailingSubstatement:
Block
EmptyStatement
ExpressionStatement
AssertStatement
SwitchStatement
...
And the definition of unreachable statements applies to all types of statements. Note specifically the following:
An empty statement can complete normally iff it is reachable.