Microsoft, everyone's favorite Java experts, had this (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vjref98/html/14_19.asp) to say about it. According to them, Java basically forbids unreachable statements, but makes an exception for if blocks so that you can do conditional compilation.
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.
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.