Serialization opt-in syntax (again)
Brian Goetz
brian.goetz at oracle.com
Mon Oct 8 12:17:11 PDT 2012
> I'm not against the idea to add a way to use & between types in Java.
> But there are several issues with the cast and the generics that already exist in Java,
> by example, a cast like (Foo<Bar> & Serializable) is unsafe and mixing type variable like T, U
> etc as bound of type variable is restricted.
I am not sure what you mean, can you give an example?
> The other problem is how do you handle the SAM conversion is you have a code that use a cast like this:
> Object o = (I & J) () -> { ... };
> at runtime, given that the meta-factory has only one SAM type.
So, in the context of a lambda, it would be a well-formed target type if it is of the form SAM&ZAM&ZAM... Arbitrary intersections of interfaces obviously would not work. If the compiler does not know what J is, then the compiler would not be able to extract enough target type information and would signal an error.
More information about the lambda-spec-observers
mailing list