groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Harvey <nathanwhar...@gmail.com>
Subject Extension method upgrades
Date Wed, 13 Dec 2017 22:09:50 GMT
Extension methods are a very powerful feature in Groovy, but they are also
difficult (and somewhat tedious) to use because they require being in
another project. I believe one reason for this limitation is the syntax of
extension methods, which are exactly the same as other methods, and so they
need to be specified as being different.

Either way, I think a huge improvement would be allowing extension methods
from within other classes on the classpath (ie not in an external
dependency). The synax for delcaring an extension method would be that of
Kotlin and other languages, for example:

public String String.upper() { 
   return this.toUpperCase() // "this" is bound
}

Another option would be to still have a parameter, if the "this" binding is
too confusing:

public String String.upper(String self) { ... }

Thoughts on adding these capabilities?



--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html

Mime
View raw message