blinker: (Default)
[personal profile] blinker
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?

Date: 2003-02-08 08:02 am (UTC)
From: [identity profile] slinkr.livejournal.com
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.

Profile

blinker: (Default)
blinker

April 2009

S M T W T F S
   1234
567891011
12131415161718
19202122232425
26 27282930  

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 26th, 2025 05:46 pm
Powered by Dreamwidth Studios