Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #10575
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Subject | Re: Question re testing constructor |
| From | Ian Shef <invalid@avoiding.spam> |
| References | <Xns9FB3682A7DBF6jpnasty@94.75.214.39> <jblc1i$n6u$1@dont-email.me> <null-20111206201830@ram.dialup.fu-berlin.de> |
| Message-ID | <Xns9FB3B1EDDE309vaj4088ianshef@138.125.254.103> (permalink) |
| Date | 2011-12-07 00:29 +0000 |
| Organization | Raytheon Company |
ram@zedat.fu-berlin.de (Stefan Ram) wrote in news:null-20111206201830 @ram.dialup.fu-berlin.de: > markspace <-@.> writes: >>On 12/6/2011 7:14 AM, Novice wrote: >>>Unfortunately, the assertTrue() statement gets flagged by the compiler as >>>being dead code. Am I right in assuming that it is essentially looking at >>>the instantiation of the HexColor class and reasoning that it will >>>inevitably create SOMETHING so that hexColor can't possibly be null, >>>therefore the assertTrue() can't ever be executed? >>I'm pretty sure, yes. > > 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). Aside: If the method being called (e.g. println()) is static, this is ugly but not an error. Discussion: The JLS seems to treat casting separately from the operations (such as calling a method) that would follow a cast. It "feels like" this doesn't need to be the case. Thus I agree with Stefan that it "feels like" the compiler or an IDE could catch this at compile time (Eclipse does not) if the JLS permitted or required it. Perhaps someone can explain why this is not the case.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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