public final class Guards extends Object
MethodHandles.guardWithTest(MethodHandle, MethodHandle, MethodHandle)
and for adjusting their method types.Modifier and Type | Method | Description |
---|---|---|
static MethodHandle |
asType |
Takes a method handle intended to be used as a guard, and adapts it to the requested type, but returning a boolean. |
static MethodHandle |
asType |
Takes a method handle intended to be used as a guard, and adapts it to the requested type, but returning a boolean. |
static MethodHandle |
getClassGuard |
Creates a guard method that tests its only argument for being of an exact particular class. |
static MethodHandle |
getIdentityGuard |
Creates a guard method that tests its only argument for being referentially identical to another object |
static MethodHandle |
getInstanceOfGuard |
Creates a guard method that tests its only argument for being an instance of a particular class. |
static MethodHandle |
isArray |
Creates a method handle that returns true if the argument in the specified position is a Java array. |
static MethodHandle |
isInstance |
Creates a method handle with arguments of a specified type, but with boolean return value. |
static MethodHandle |
isInstance |
Creates a method handle with arguments of a specified type, but with boolean return value. |
static MethodHandle |
isNotNull() |
Returns a guard that tests whether the first argument is not null. |
static MethodHandle |
isNull() |
Returns a guard that tests whether the first argument is null. |
static MethodHandle |
isOfClass |
Creates a guard method handle with arguments of a specified type, but with boolean return value. |
public static MethodHandle isOfClass(Class<?> clazz, MethodType type)
clazz
- the class of the first argument to test fortype
- the method typepublic static MethodHandle isInstance(Class<?> clazz, MethodType type)
clazz
- the class of the first argument to test fortype
- the method typepublic static MethodHandle isInstance(Class<?> clazz, int pos, MethodType type)
clazz
- the class of the first argument to test forpos
- the position on the argument list to testtype
- the method typepublic static MethodHandle isArray(int pos, MethodType type)
pos
- the position in the argument littype
- the method type of the handlepublic static MethodHandle asType(MethodHandle test, MethodType type)
MethodHandle.asType(MethodType)
to convert types and uses MethodHandles.dropArguments(MethodHandle, int, Class...)
to match the requested type arity.test
- the test method handletype
- the type to adapt the method handle topublic static MethodHandle asType(LinkerServices linkerServices, MethodHandle test, MethodType type)
LinkerServices.asType(MethodHandle, MethodType)
to convert types and uses MethodHandles.dropArguments(MethodHandle, int, Class...)
to match the requested type arity.linkerServices
- the linker services to use for type conversionstest
- the test method handletype
- the type to adapt the method handle topublic static MethodHandle getClassGuard(Class<?> clazz)
clazz
- the class to test for.public static MethodHandle getInstanceOfGuard(Class<?> clazz)
clazz
- the class to test for.public static MethodHandle getIdentityGuard(Object obj)
obj
- the object used as referential identity testpublic static MethodHandle isNull()
public static MethodHandle isNotNull()
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/jdk.dynalink/jdk/dynalink/linker/support/Guards.html