java - Lambda and cast intersection type (Eclipse compiler bug) -
so, why code compile?
public static void main(string[] args) { calculator test = (calculator & sumator) (a, b) -> + b; system.out.println(test.calculate(2, 3)); sumator sumator = (calculator & sumator) (a, b) -> + b; // compile, throws exception sumator.test(); both both = (both) (a, b) -> + b; // not compile } interface calculator { public int calculate(int a, int b); } interface sumator { public int test(); public int test3(int a, int b); } // intersection of both types interface both extends sumator, calculator { }
this sort of misleading, know casting intersection type, i've read jls, still confusing.
it sort of makes sense why
serializable & comparable
would compile, since result (the synthetic type) between 2 functional interface, why :
calculator & sumator
works? synthetic type not functional interface.
this bug in eclipse has been fixed milestone 6 towards eclipse neon (4.6).
Comments
Post a Comment