Method and Field Literals

John Rose john.r.rose at oracle.com
Tue Jun 19 20:50:46 UTC 2018


On Jun 19, 2018, at 11:40 AM, Remi Forax <forax at univ-mlv.fr> wrote:
> 
> BTW, if we want to support MethodHandle (or j.l.r.Method) at some point, we should re-use the same idea we use for the Serialization, use a non-conventional cast:
>  MethodHandle mh = (MethodHandle & Predicate<String>)String::isEmpty;
> 
> with Predicate<String> used only to provide the necessary type information, this has the advantage of not requiring to change the grammar thus lowering the cost to introduce such feature.

After the above code executes I would *not* expect the following to be true:

  assert(mh instanceof Predicate);

So there's something fishy about the cast to the conjunctive type:  It doesn't
yield an expression value of the type claimed by the cast.

One possible fix:  Declare that such casts are themselves poly expressions,
to the extent that they are allowed to drop the "inconvenient" part of the type,
for certain target types like MH.

— John


More information about the discuss mailing list