Virtual extension methods -- a strawman design

Brian Goetz brian.goetz at oracle.com
Mon May 17 06:58:39 PDT 2010


> It is the year 2003. Sun is planning JDK 5. Due to many complaints of
> Java programmers, Sun decides that a 'sort' method was needed in
> java.util.List. They introduce a new
>
> interface List2 extends List {
>    public void sort(Comparator<? super E>  comparator);
> }
>
> and have all JDK List-classes implement List2 instead of only List.
> They encourage the use of List2 in the API Doc.
>
> There would have been no compatibility issues at all. Programmers
> would have adopted List2 whenenver they were writing new code.

And in user code, people would have inserted casts to List2 whenever they 
encountered a List, sometimes with an instanceof check first, sometimes 
without.  That would not be good for the readability or maintainability of 
Java code.



More information about the lambda-dev mailing list