Change regarding conditional expression & capture & lub?

Dan Smith daniel.smith at oracle.com
Mon Dec 9 12:40:17 PST 2013


On Dec 8, 2013, at 8:56 AM, Stephan Herrmann <stephan.herrmann at berlin.de> wrote:

> This doesn't seem directly connected to JSR 335 but I wonder
> if the following change in behavior has s.t. to do with the
> type checking we are discussing here:
> 
>  class A{/**/}
>  class B extends A {/**/}
> 
>  class G<T> {
>    G<B> gb=null;
>    G<? super A> gsa=null;
>    G<? super B> l = (true)? gsa : gb;
>  }
> 
> javac7- rejects this, which corresponds to my understanding of the JLS:
> 
> (1) capture the types of gsa and gb, respectively.
> (2) compute the lub
> (3) detect type mismatch
> 
> javac8, OTOH, accepts the snippet.
> 
> Has the specification for any of the three steps been changed?

Yes!  Conditional expressions can be poly expressions.  See Part D, 15.25.

The relevant change is that poly conditionals do not perform lub at all.  Instead, they simply check that each branch is compatible with the target type, and then consider the expression to have the same type as its target type.

—Dan


More information about the lambda-spec-observers mailing list