Allow method bodies

Howard Lovatt howard.lovatt at gmail.com
Sat May 15 19:06:38 PDT 2010


The proposal for extension methods allows for the extension method
forwarding to a static method, e.g.:

  public interface List<T> {
    boolean add(T t);
    // The rest of the existing List methods

    extension void sort() default Collections.<T>sort;
  }

A more flexible and more natural alternative is to allow a body definition:

  void sort() { Collections.sort( this ); }

This is easy to implement also; you don't need a new class file
format. You can translate this into:

  public interface List<T> {
    boolean add(T t);
    // The rest of the existing Collection methods

    void sort();

    public static final class $$Trait {
      public static void sort( final List self ) { Collections.sort( self ); }
    }
  }


  -- Howard.


More information about the lambda-dev mailing list