While browsing the Java 7 API documentation I stumbled upon the new class java.lang.ClassValue with the following rather minimal documentation:
Lazily associate a computed value with (potentially) every type. For example, if a dynamic language needs to construct a message dispatch table for each class encountered at a message send call site, it can use a
ClassValue
to cache information needed to perform the message send quickly, for each class encountered.
Can anyone give a better explanation of what problem this class solves and perhaps some sample code or open source project that already uses this class?
Update: I'm still interested in some actual source code or examples using this new class.
I also found this mail on the mlvm-dev mailing list concerning some implementation improvements. It was apparently changed from using a WeakHashMap to a new private field on java.lang.Class to make it more scalable.
get()
method is the the best place for clues. I don't understand why theget()
method is given aClass
object, however. – Raedwald Sep 16 '11 at 12:12