Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #10580

Re: Question re testing constructor

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Joshua Cranmer <Pidgeot18@verizon.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Question re testing constructor
Date Tue, 06 Dec 2011 22:57:19 -0600
Organization A noiseless patient Spider
Lines 47
Message-ID <jbmrnj$26t$1@dont-email.me> (permalink)
References <Xns9FB3682A7DBF6jpnasty@94.75.214.39> <jblc1i$n6u$1@dont-email.me> <null-20111206201830@ram.dialup.fu-berlin.de> <Xns9FB3B1EDDE309vaj4088ianshef@138.125.254.103> <unreachable-code-20111207032302@ram.dialup.fu-berlin.de>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
Injection-Date Wed, 7 Dec 2011 04:57:23 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="WpcHJSul77m+zlbR9GVqkA"; logging-data="2269"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+t4w6YG+h6ywfAFAbFGATwwIs84+tnH+0="
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0
In-Reply-To <unreachable-code-20111207032302@ram.dialup.fu-berlin.de>
Cancel-Lock sha1:j9Lx3YfoyuOaiUhPw+SWVr5lMBc=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10580

Show key headers only | View raw


On 12/6/2011 8:24 PM, Stefan Ram wrote:
> Ian Shef<invalid@avoiding.spam>  writes:
>> ram@zedat.fu-berlin.de (Stefan Ram) wrote in news:null-20111206201830
>> @ram.dialup.fu-berlin.de:
>>> If the Java compiler is so smart at detecting null values,
>>> why does he not also give an error on code like:
>>> (( java.io.PrintStream )null ).println()
>>> ?
>> Short answer:  Because the JLS says so.  (see the third edition, paragraph
>> 15.16 where it is explained that most casts are handled at run time).
>
>    Something similar:
>
>    It is difficult for me to forecast an »unreachable statement« error.
>    For example, I would have expected such an error for
>
> public class Main
> { public static void main( final java.lang.String[] args )
>    { java.lang.System.out.println( "alpha3" );
>      if( true )return;
>      java.lang.System.out.println( "beta3" ); }}
>
>    , but did *not* get one, however, the compiler knows that the
>    beta3 statement *is* unreachable, because he does not care to
>    compile it.

IIRC, the JLS actually describes why this case does not generate an 
unreachable code exception. The idea is to permit what is, in essence, 
conditional compilation:

class Foo {
   public final static bool DEBUG = false;

   public void frozinate() {
     if (DEBUG)
       log("Frozinating...");
     // ... do real work ...
   }
}

By handling this case, you could switch the value of DEBUG to select or 
unselect some code to be run at runtime; you shouldn't have to eradicate 
all if(DEBUG) code whenever you throw the switch to false.

-- 
Beware of bugs in the above code; I have only proved it correct, not 
tried it. -- Donald E. Knuth

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Question re testing constructor Novice <novice@example..com> - 2011-12-06 15:14 +0000
  Re: Question re testing constructor markspace <-@.> - 2011-12-06 07:23 -0800
    Re: Question re testing constructor Novice <novice@example..com> - 2011-12-06 17:17 +0000
    Re: Question re testing constructor Tom Anderson <twic@urchin.earth.li> - 2011-12-06 21:25 +0000
    Re: Question re testing constructor Ian Shef <invalid@avoiding.spam> - 2011-12-07 00:29 +0000
      Re: Question re testing constructor Patricia Shanahan <pats@acm.org> - 2011-12-06 19:28 -0800
      Re: Question re testing constructor Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-12-06 22:57 -0600
      Re: Question re testing constructor Lew <lewbloch@gmail.com> - 2011-12-07 07:12 -0800
      Re: Question re testing constructor Lew <lewbloch@gmail.com> - 2011-12-07 07:14 -0800
        Re: Question re testing constructor Ian Shef <invalid@avoiding.spam> - 2011-12-07 15:59 +0000
          Re: Question re testing constructor Ian Shef <invalid@avoiding.spam> - 2011-12-08 19:19 +0000
      Re: Question re testing constructor ilAn <idonot@wantspam.net> - 2011-12-07 20:41 +0200
  Re: Question re testing constructor Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-12-06 07:34 -0800
    Re: Question re testing constructor Novice <novice@example..com> - 2011-12-06 17:15 +0000
  Re: Question re testing constructor Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-12-06 09:49 -0800
  Re: Question re testing constructor Roedy Green <see_website@mindprod.com.invalid> - 2011-12-06 16:40 -0800
  Re: Question re testing constructor Henk van Voorthuijsen <voorth@xs4all.nl> - 2011-12-07 00:33 -0800

csiph-web