i think the only thing anything like it is the only way to add methods to a class in java: extend it (as in subclass it). Send an object to your library code that it's going to do getClass().getMethods() to, effectively. You can do that from groovy (the subclass for instance can be written in groovy) but at bytecode level it basically has to be in the fixed definition of the class, so there's nothing specifically groovy about it.
*Maybe* you can generate those groovy subclasses at runtime using the scripting api. (generate a script that defines the class and returns the instance...) The library has to be a bit unfussy about the originating classloader of course... -- Rachel Greenham rac...@merus.eu > On 26 Aug 2021, at 15:34, o...@ocs.cz wrote: > > Rachel, > > yes, I use the metaclass stuff heavily; but I am often bumping into problems > with library code which accesses attributes of my classes through reflexion > (and due to that, does not see my dynamically installed accessors etc). > > I know the Javas of old did not support that; but I sort of hoped today's one > just might. Today's Groovy just might not exploit it normally due to the > backward compatibility with the metaclass stuff which used to be the only way > to get runtime metaprogramming originally, when Groovy has been created. > > Looks like bad luck :( > > Thanks, > OC > >> On 26. 8. 2021, at 15:43, Rachel Greenham <rac...@merus.eu >> <mailto:rac...@merus.eu>> wrote: >> >> Through java.lang.reflect? I'd guess not as that would involve actually >> changing the bytecode of a loaded class at runtime to add methods... It's >> just not a JVM thing, I think - if it was, at least by any official means, >> Groovy would probably have been written to use it instead of all the stuff >> it does with metaclasses. >> >> But if you're all in groovy, you can add methods dynamically using expando i >> think and then they're findable through *Groovy's* metaclass apis... but no, >> they won't be findable/reflectable by Java code. >> >> -- >> Rachel Greenham >> rac...@merus.eu <mailto:rac...@merus.eu> >> >>> On 26 Aug 2021, at 14:35, o...@ocs.cz <mailto:o...@ocs.cz> wrote: >>> >>> Hi there, >>> >>> the subject says it all. I've asked this long time ago (and got a negative >>> answer then), but meantime there's Groovy 3. >>> >>> Is there now a way to do that? >>> >>> Most important it would be with my own class (subclass of a library class), >>> if it helps to find a solution. >>> >>> Thanks, >>> OC >>> >> >