Jorge Ortiz, Christos Loverdos and myself have a slumbering Scala Improvement Proposal to include what you call "extension methods" to Scala code.
We've experimented with different syntax and it depends on how you want it to work. I was pulling toward a more "type selector" based mechanism like the following: def [T <: String].isDigitsOnly() = this.matches("^\\d$") where the prefixing type declaration selects which types are allowed to be attached to basically it's syntactic sugar over: def isDigitsOnly[T <: String]( t : T) = t.matches("^\\d$") so it's basically possible to call it using: isDigitsOnly("blah") and as "blah".isDigitsOnly() Well well, I'm crazy-talking again. Cheers, Viktor On Tue, Feb 24, 2009 at 4:39 AM, Mark Derricutt <m...@talios.com> wrote: > How about stealing/reusing the C# idiom of a "this" parameter: > > public class MyList { > public static void sort(this List<T>, Comparator<T> comparator) { > .. > } > } > > Which compiles to the same as you suggest, being > > new List().sort(comparator) being > > MyList.sort(new List(), comparator); > > This could also play well with introducing "this" as a return type for > chaining. > > ...and then Buffy staked Edward. The End. > > > On Tue, Feb 24, 2009 at 4:33 PM, Reinier Zwitserloot > <reini...@gmail.com>wrote: > >> @Extension public static <T> void sort(List<T> list, Comparator<T> >> comparator) { /* code */ } >> > > > > > -- Viktor Klang Senior Systems Analyst --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to javaposse@googlegroups.com To unsubscribe from this group, send email to javaposse+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/javaposse?hl=en -~----------~----~----~----~------~----~------~--~---