Attila Szegedi wrote:
> In my opinion, the vast majority of these woes would be eliminated if  
> Class would have a map for custom values exposed to user code.  
> Something not unlike how ThreadLocal works for per-thread state  
> ("ClassLocal"?)

As with many things in JRuby, I hacked this exact use case using 
reflection on a Sun JDK. Basically I did the following:

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

Once you've done this, you can access the "attached" data by simply 
requesting the TypeHolder.class annotation from the Class object and 
casting it back to TypeHolderImpl.

Hacky, sure. But it worked. I'm not using it for anything at present.

- Charlie

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to