Why does my Java compiler (jikes) reject "return;" in the middle of a method on the grounds that it makes the rest of the method unreachable, and yet not so much as warn me about " if (true) { return; }" which makes the rest of the method equally unreachable?
no subject
Date: 2003-02-08 08:02 am (UTC)I don't know if I think that's a good thing or a bad thing. I suppose it's good that I can't accidentally chop out half a method by putting in a poorly placed return statement. On the other hand, I only run into this situation when I'm deliberately attempting to chop out half a method.
The unreachable statement thingy also drives me nuts in switch statements because as a C programmer I learned that you always put "break" at the end of a case, but in Java you can't use "break" if you're returning from that case (which makes the break unreachable). It just looks wrong to have a switch statement with no breaks, even if I know it's not going to fall through.