On 28.08.21 14:46, OCsite wrote:
Rachel, Paul,
thanks a lot!
Pity not even today's Java supports something like Objective-C runtime
support for managing the methods in a class :(
Anyway, I might try to create my (sub)classes dynamically at runtime —
this is an idea which did not occur to me before; and although I can see
some hurdles (for one, the classes which I need most to support dynamic
methods/properties are database classes; and the source from which I
read in the information of dynamic methods is... the very database; I'll
have to find some trick here), it looks pretty promising.
Java does offer you in a very limited way to add a method at runtime by
using an agent and instrumentation. However:
"""
Instances of the redefined class are not affected.
The redefinition may change method bodies, the constant pool and
attributes (unless explicitly prohibited). The redefinition must not
add, remove or rename fields or methods, change the signatures of
methods, or change inheritance. The redefinition must not change the
NestHost or NestMembers attributes.
"""
from
https://docs.oracle.com/en/java/javase/11/docs/api/java.instrument/java/lang/instrument/Instrumentation.html#redefineClasses(java.lang.instrument.ClassDefinition...)
Of course you can also redefine the class on loading, then you can
basically do whatever.
But for Groovy in general I found this always much too limiting.
bye Jochen