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


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

Re: A hypothetical compiler extension

From Jan Burse <janburse@fastmail.fm>
Newsgroups comp.lang.java.programmer
Subject Re: A hypothetical compiler extension
Date 2015-10-27 23:02 +0100
Organization albasani.net
Message-ID <n0osa2$v6d$1@news.albasani.net> (permalink)
References <extension-20151027221547@ram.dialup.fu-berlin.de>

Show all headers | View raw


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.
>

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


Thread

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

csiph-web