public class ClassInfoCache extends Object
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
ClassInfoCache.ClassInfo |
| Constructor and Description |
|---|
ClassInfoCache() |
| Modifier and Type | Method and Description |
|---|---|
static ClassInfoCache.ClassInfo |
get(Class<?> cls) |
static Class |
getEnumClass(ClassInfoCache.ClassInfo cinfo,
Class cls)
Find the class that is an enum in the superclass chain starting at cls.
|
public static ClassInfoCache.ClassInfo get(Class<?> cls)
public static Class getEnumClass(ClassInfoCache.ClassInfo cinfo, Class cls)
cinfo - ClassInfo for clscls - Class which may have java.lang.Enum in its superclass chain.Copyright © 2017–2019 Eclipse Foundation. All rights reserved.