Different behavior between (F) and (Object & F)

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Nov 8 05:39:43 PST 2012


This glitch is due to the fact that translation code for lambdas whose 
target is an intersection type is not there yet. So, as a short-time 
hack, we adopted the view that the first type of an intersection types 
dictates how lambda conversion should work. This is all temporary and 
will be removed.

Maurizio

On 08/11/12 07:45, bitter_fox wrote:
> Hi,
> There is a different behavior in the same semantics:
>
> public class Main
> {
>      interface F
>      {
>          void m();
>          default void clone() throws CloneNotSupportedException {}
>      }
>
>      public static void main(String[] args)
>      {
>          Object o;
>
>          // implicit Object
>          o = (F) () -> {}; // pass compiler check
>
>          // explicit Object
>          o = (Object & F) () -> {}; // compile time error
>      }
> }
>
> Compiler rejects "(Object & F) () -> {}", but it accepts "(F) () -> {}".
> Is this the correct behavior?
>
> This is the compile error by "(Object & F) () -> {}":
>
> Main.java:18: error: clone() in Object cannot implement clone() in F
>                  o = (Object & F) () -> {}; // compile time error
>                      ^
>    attempting to assign weaker access privileges; was public
> 1 error
>
> Regards,
> bitter_fox
>



More information about the lambda-dev mailing list