Charles Oliver Nutter schrieb: > Jochen Theodorou wrote: >> but this works only for classes that you can change. If it is a class >> coming from some parent loader, that you have no control over, then it >> won't work.. or do I see that wrong? >> >> Maybe the typical usage scenario is different here with Groovy > > No, this works for all classes, but you have to subvert reflection and > have appropriate security allowances. I'm actually modifying state > inside the java.lang.Class objects themselves.
oh? I guess I should reread your post carefully to see why it is possible for for example java.lang.String... you wrote: > 1. Create a "TypeHolder" annotation > 2. Create a "TypeHolderImpl" class that acts as a reference holder > 3. Make "TypeHolderImpl" implement the "TypeHolder" annotation interface > (requires code generation, obviously) > 3. Using reflection, forcibly insert a "TypeHolderImpl" instance into > the java.lang.Class annotation table Creating an annotation is sure no problem. And TypeholderImpl... I didn't grasp that the VM allows you to implement an annotation interface... interesting. But ok... The third step is unclear to me. How do I forcibly insert my implementation into the Class annotation table? I would assume you mean getAnnotations() and then change the returned array... no, that cannot be it... so what is the trick? > Like I said, it's a hack, but it saves you associating state with Class > objects in an external structure. If the java.lang.Class object goes > away, so does your data. well, we have to hack all the time to go around limitations of the VM, don't we ;) bye Jochen -- Jochen "blackdrag" Theodorou The Groovy Project Tech Lead (http://groovy.codehaus.org) http://blackdragsview.blogspot.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "JVM Languages" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/jvm-languages?hl=en -~----------~----~----~----~------~----~------~--~---
