PRE-PROPOSAL: Extension methods

Rémi Forax forax at univ-mlv.fr
Thu Mar 19 08:10:31 PDT 2009


I vote NO.
The problem with extension method is that it doesn't mix well with 
polymorphism.

Example:
interface List {
  ...
}

class Collections {
  public static void sort(this List<?> list) {   // extension methods
    ...   // 1
  }
}

class SortedList implements List {
  public void sort() {
    ... // 2
  }
}

import static java.util.Collections.*;
...
List<Integer> list=...
list.sort();   // call  1

SortedList<Integer> slist=...
slist.sort(); // call 2

List<Integer> slist2=slist;
slist2.sort();  // call 1

The last call is not intuitive in a well known language in which late 
binding
is the default behavior.

Rémi



More information about the coin-dev mailing list