PROPOSAL: language support for JSR 292

Howard Lovatt howard.lovatt at iee.org
Fri May 1 02:16:48 PDT 2009


Hi John,

Great work on the proposal.

There appears to be four controversial points about the proposal:

1. The use of Void as a bottom type; this seems most natural to me and
I would like to see this throughout Java (in fact I have suggested
this before on I think Alex Buckley's blog).

2. Making InvokeDynamic a normal uninstantiatable type (like
Collections); again this seems fine to me, no need for the compiler to
issue a warning it doesn't for T extends Collections and that isn't a
problem

3. The use of primatives in angle brackets for return types; if people
don't like that you could use a cast to indicate return type (like you
would for a null argument for example when disambiguating overloaded
methods)

4. The throwing of checked exceptions; probably OK, the top level data
loggers that I have seen have caught Exception or above so I don't
think this will be a problem in practice

At a higher level, rather than details of the proposal, it would be a
nice addition to have a convenience interface, lets for the sake of
argument call it Dynamic, that behaved like a top level class in a
dynamic language and you implicitly had to define a private static
missingMethod method in any class that implemented Dynamic. Then a
class that implemented Dynamic or any class that used an object of
type Dynamic would be converted automatically be the compiler to use
InvokeDynamic, e.g. your simple example would become:

public class Hello implements Dynamic {
  public void greet( final String... av ) {
    if ( av.length == 0 ) av = new String[] { "world" };
    for ( final String whom : av ) {
      hail( whom ); // transtated to InvokeDynamic.hail( whom ) by
compiler - instance method and this is a Dynamic
    }
  }

  void greeter( final String x ) { System.out.println( "Hello, " + x ); }

  private static final MethodHandle missingMethod( final CallSite
site, final Object... args ) {
    return ...
  }


  // Following two constructs added automatically by the compiler

  static { Linkage.registerBootstrapMethod("bootstrapInvokeDynamic"); }

  private static Object bootstrapInvokeDynamic( final CallSite site,
final Object... args ) {
    final MethodHandle target = missingMethod( site, args );
    site.setTarget( target );
    return MethodHandles.invoke( target, args );
  }
}


Keep up the good work,

 -- Howard.



More information about the coin-dev mailing list