Points about language support for 292

Alex Buckley Alex.Buckley at Sun.COM
Fri May 1 10:57:00 PDT 2009

Rémi Forax wrote:
> Question: why do we need to use a type InvokeDynamic ?
> The invokedynamic instruction is a function call,
> so I propose to use a syntax more close to a function call,
> something like:
> $aDynamicFunction(arg1, arg2)

There are so many implications of blindly inventing this new syntax, I 
don't know where to start. Java doesn't have the concept of a function 
or a function call, so you need to define it. If the answer is "Function 
call just translates to an invokedynamic instruction", then you've 
introduced a new kind of expression where an existing one - method 
invocation - would do.

> Now, the problem of the return type.
> I propose the following rules:
> - if the dynamic call is the righ part of an assignation, the return type
>   is the type of the lhs.
>   int value = $aDynamicFunction(param1, param2)         // -> int
> - if the dynamic call is prefixed by a cast, the return type is the
>  type of the cast (note that this rule doesn't exist for generics)
>  (double)$aDynamicFunction(param1, param2)         // -> double
> - else the return type is Object.

You know I am suspicious of inference :-)

The cast idea is appealing at first but it breaks our old friend, 
Tennent's Correspondence Principle. You cannot write:

   int x = (int)InvokeDynamic.foo(..);

and later decide to introduce some abstraction:

   int x = (int)m();
   Object m() { return InvokeDynamic.foo(..); }

because Object doesn't cast to int very well.

Your method would have to be:

   InvokeDynamic m() { return (InvokeDynamic)InvokeDynamic.foo(...); }

which might be, well, alright, OK, it's not the end of the world.

A default return type of Object is well established, of course.


More information about the coin-dev mailing list