Class ClassInfoCache
All of the isA methods on ClassInfo need to be passed the same Class that was used in the get call! This is an awkward interface, but the alternative is to store the class in the ClassInfo, which would create a strong reference from the value to the key, making the WeakHashMap useless. It also appears to be difficult to use a weak or soft reference here, because I can't handle the case of an empty reference to the class inside the ClassInfo object. If ClassInfoCache supported the methods directly, we could work around this, but then we would in some case be doing multiple lookups for a class to get class information, which would slow things down significantly (the get call is a significant cost in the benchmarks).
XXX There is a better solution: add MORE information to the cache. In particular, use a ClassAnalyzer to construct the linearized inheritance chain (order doesn't matter in this case, but we already have the implementation) and implement all of the isA methods by a simple check on whether the class is in the chain (or perhaps convert to Set). We can statically fill the cache with all of the basic objects (e.g. Streamable, Serializable, etc.) needs in a static initializer.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ClassInfoCache.ClassInfo
static Class
getEnumClass
(ClassInfoCache.ClassInfo cinfo, Class cls) Find the class that is an enum in the superclass chain starting at cls.
-
Field Details
-
classData
-
-
Constructor Details
-
ClassInfoCache
public ClassInfoCache()
-
-
Method Details
-
get
-
getEnumClass
Find the class that is an enum in the superclass chain starting at cls. cinfo MUST be the ClassInfo for cls.- Parameters:
cinfo
- ClassInfo for clscls
- Class which may have java.lang.Enum in its superclass chain.- Returns:
- A class for which isEnum() is true, or null if no such class exists in the superclass chain of cls.
-