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


Groups > comp.lang.java.programmer > #32946 > unrolled thread

Re: A hypothetical compiler extension

Started byJan Burse <janburse@fastmail.fm>
First post2015-10-27 23:02 +0100
Last post2015-10-27 23:02 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.java.programmer

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: A hypothetical compiler extension Jan Burse <janburse@fastmail.fm> - 2015-10-27 23:02 +0100

#32946 — Re: A hypothetical compiler extension

FromJan Burse <janburse@fastmail.fm>
Date2015-10-27 23:02 +0100
SubjectRe: A hypothetical compiler extension
Message-ID<n0osa2$v6d$1@news.albasani.net>
IntelliJ does this already.

Stefan Ram schrieb:
>    The following is hypothetical AFAIK, but wouldn't it be nice?
>
>    One calls
>
> javac -Xlint:null
>
>    and then
>
> void m( final java.lang.Object o )
> { java.lang.System.out.println
>    ( o.toString() ); }
>
>    gives
>
>    ( o.toString() ); }
>      ^
> Warning: o might be null.
>
>    . One rewrites to
>
> void m( final java.lang.Object o )
> { if( o != null )
>    java.lang.System.out.println
>    ( o.toString() ); }
>
>    and the warning disappears.
>
>    Javac alread has path-value-analysis as it already can
>    detect when a path of execution of a method (think of
>    nested ifs) accesses a variable that has not been
>    defined yet in this path.
>
>    We also could have
>
> javac -Xlint:0
>
> void m( final int i )
> { java.lang.System.out.println( 1/i ); }
>                                    ^
> Warning: i might be zero.
>
> void m( final int i )
> { if( i != 0 )
>    java.lang.System.out.println( 1/i ); }
>
>    That would give you more security, but you could stay within
>    the bounds of Java and would not have to be forced to use,
>    for example, Scala.
>

[toc] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web