As Rachel said, methods/properties added via runtime metaprogramming will
only be visible to Groovy's reflection capabilities. Some frameworks have
moved to using compile-time metaprogramming (AST transforms, macros/macros
methods) or traits so that added features will be visible also to Java.

Cheers, Paul.

On Fri, Aug 27, 2021 at 12:34 AM o...@ocs.cz <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> 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
>
> On 26 Aug 2021, at 14:35, 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
>
>
>
>

Reply via email to