Edmund Price Edmund Price - 2 months ago 9
Java Question

This code does not compile due to an unreachable statement

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?

Answer

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 ;).