--- old/src/java.base/share/classes/java/lang/Class.java 2015-01-10 13:43:09.635162120 +0100 +++ new/src/java.base/share/classes/java/lang/Class.java 2015-01-10 13:43:09.536164093 +0100 @@ -69,6 +69,8 @@ import sun.security.util.SecurityConstants; import java.lang.annotation.Annotation; import java.lang.reflect.Proxy; +import java.util.function.Function; + import sun.reflect.annotation.*; import sun.reflect.misc.ReflectUtil; @@ -2562,6 +2564,27 @@ return (genericInfo != ClassRepository.NONE) ? genericInfo : null; } + /** + * If this Class represents a generic class or interface, then the result of + * applying given function to this Class object is returned, otherwise null. + * The result is cached in per-Class map using identity of given key. + * In case of races, the function may be invoked multiple times for the same + * key, therefore it should be idempotent. + * + * @param key the non-null key who's identity is used for caching of the result + * @param function the function applied to this Class to compute the result + * @param the type of result + * @return the cached result of applying given function to this Class or null + * @throws java.lang.NullPointerException if given key or function is null + */ + D getGenericDerivative(Object key, Function, ? extends D> function) { + if (key == null || function == null) throw new NullPointerException(); + ClassRepository genericInfo = getGenericInfo(); + return (genericInfo == null) + ? null + : genericInfo.getDerivative(this, key, function); + } + // Annotations handling native byte[] getRawAnnotations(); // Since 1.8