8288730: Add type parameter to Lookup::accessClass and Lookup::ensureInitialized
Reviewed-by: mchung
This commit is contained in:
parent
37774556da
commit
a2d8f634de
src/java.base/share/classes/java/lang/invoke
@ -422,8 +422,7 @@ public final class ConstantBootstraps {
|
||||
|
||||
private static <T> Class<T> validateClassAccess(MethodHandles.Lookup lookup, Class<T> type) {
|
||||
try {
|
||||
lookup.accessClass(type);
|
||||
return type;
|
||||
return lookup.accessClass(type);
|
||||
}
|
||||
catch (ReflectiveOperationException ex) {
|
||||
throw mapLookupExceptionToError(ex);
|
||||
|
@ -2811,6 +2811,7 @@ assertEquals("[x, y, z]", pb.command().toString());
|
||||
* This method returns when {@code targetClass} is fully initialized, or
|
||||
* when {@code targetClass} is being initialized by the current thread.
|
||||
*
|
||||
* @param <T> the type of the class to be initialized
|
||||
* @param targetClass the class to be initialized
|
||||
* @return {@code targetClass} that has been initialized, or that is being
|
||||
* initialized by the current thread.
|
||||
@ -2826,7 +2827,7 @@ assertEquals("[x, y, z]", pb.command().toString());
|
||||
* @since 15
|
||||
* @jvms 5.5 Initialization
|
||||
*/
|
||||
public Class<?> ensureInitialized(Class<?> targetClass) throws IllegalAccessException {
|
||||
public <T> Class<T> ensureInitialized(Class<T> targetClass) throws IllegalAccessException {
|
||||
if (targetClass.isPrimitive())
|
||||
throw new IllegalArgumentException(targetClass + " is a primitive class");
|
||||
if (targetClass.isArray())
|
||||
@ -2926,8 +2927,9 @@ assertEquals("[x, y, z]", pb.command().toString());
|
||||
* <p>
|
||||
* Otherwise, {@code targetClass} is not accessible.
|
||||
*
|
||||
* @param <T> the type of the class to be access-checked
|
||||
* @param targetClass the class to be access-checked
|
||||
* @return the class that has been access-checked
|
||||
* @return {@code targetClass} that has been access-checked
|
||||
* @throws IllegalAccessException if the class is not accessible from the lookup class
|
||||
* and previous lookup class, if present, using the allowed access modes.
|
||||
* @throws SecurityException if a security manager is present and it
|
||||
@ -2936,7 +2938,7 @@ assertEquals("[x, y, z]", pb.command().toString());
|
||||
* @since 9
|
||||
* @see <a href="#cross-module-lookup">Cross-module lookups</a>
|
||||
*/
|
||||
public Class<?> accessClass(Class<?> targetClass) throws IllegalAccessException {
|
||||
public <T> Class<T> accessClass(Class<T> targetClass) throws IllegalAccessException {
|
||||
if (!isClassAccessible(targetClass)) {
|
||||
throw makeAccessException(targetClass);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user