Thank you, Jochen - that's actually a Groovy feature that has been around for a long time, that I completely forgot about :-)

https://groovy-lang.org/metaprogramming.html#_extension_modules
https://mrhaki.blogspot.com/2013/01/groovy-goodness-adding-extra-methods.html

Do you know if:

1. This works for interfaces (e.g. List and Map) ?
2. Whether IntelliJ picks up those extension methods (i.e. will
   Intellisense know that e.g. List now has a getSize() method) ?

Cheers,
mg


On 05/08/2020 09:34, Jochen Theodorou wrote:
On 04.08.20 16:13, MG wrote:
On 04/08/2020 15:16, Basurita wrote:
On 8/1/20 14:41, MG wrote:
Hmmm, I am for consistency, but at least I use very few maps as
compared to lists, and rarely ever output the size of a map, but
constantly for
lists, so having getSize() on List would still be beneficial.
You're free to add whatever you want to your metaClass :-)

In dynamic Groovy, yes, but I am an IntelliJ / @CompileStatic Groovy
user so afaiaao there is no way to make this work in my case...

for @CompileStatic this can be done via extension methods.

Afaik it is still the case, that the classes containing extension
methods must be compiled before their use in a separate compilation so
the compiler can pick them up as part of the compilation once you want
to use them.


bye Jochen

Reply via email to