Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This code does not compile due to an unreachable statement [closed]

Tags:

java

I've tried my utmost to reproduce this in another way, but it seems that only this line gives the error (please excuse the comment):

return foo.containsKey(MARKET_DATA) && !foo.get(MARKET_DATA).isMissing();/*mapping code can inject a Missing type*/;

However I type this it gives me an error: "unreachable statement". Why is this?

like image 792
Edmund Price Avatar asked Dec 14 '22 03:12

Edmund Price


1 Answers

This is clear if you remove the comment:

return foo.containsKey(MARKET_DATA) && !foo.get(MARKET_DATA).isMissing();;

Note well the two semicolons at the end: empty statements are allowed in Java, but this particular empty statement is unreachable as the previous statement always returns.

(For the avoidance of doubt, a comment should not be terminated with a ;).

like image 154
Bathsheba Avatar answered May 23 '23 08:05

Bathsheba