While browsing the Java 7 API documentation I stumbled upon the new class java.lang.ClassValue with the following rather minimal documentation:
Lazily
ClassValue cache something about the class.
Here is a part of code (at Lucene 5.0 AttributeSource.java):
/** a cache that stores all interfaces for known implementation classes for performance (slow reflection) */
private static final ClassValue[]> implInterfaces = new ClassValue[]>() {
@Override
protected Class extends Attribute>[] computeValue(Class> clazz) {
final Set> intfSet = new LinkedHashSet<>();
// find all interfaces that this attribute instance implements
// and that extend the Attribute interface
do {
for (Class> curInterface : clazz.getInterfaces()) {
if (curInterface != Attribute.class && Attribute.class.isAssignableFrom(curInterface)) {
intfSet.add(curInterface.asSubclass(Attribute.class));
}
}
clazz = clazz.getSuperclass();
} while (clazz != null);
@SuppressWarnings({"unchecked", "rawtypes"}) final Class extends Attribute>[] a =
intfSet.toArray(new Class[intfSet.size()]);
return a;
}
};