Different behavior between (F) and (Object & F)
bitter_fox
bitterfoxc at gmail.com
Wed Nov 7 23:45:10 PST 2012
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