Class UnsafeAccess
java.lang.Object
dev.derklaro.reflexion.internal.unsafe.UnsafeAccess
A utility class which allows access to sun.misc.Unsafe without needing to hassle with it. To verify that this util is
ready to be used, use the
isAvailable() method.- Since:
- 1.6
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @UnknownNullability ObjectinvokeMethod(@NotNull String methodName, @NotNull Class<?>[] argTypes, @NotNull Object... args) Calls the given method which is provided in sun.misc.Unsafe.static booleanChecks if the sun.misc.Unsafe instance could be resolved during the class init, and is now ready to call method with it.
-
Field Details
-
THE_UNSAFE
-
-
Constructor Details
-
UnsafeAccess
private UnsafeAccess()
-
-
Method Details
-
isAvailable
public static boolean isAvailable()Checks if the sun.misc.Unsafe instance could be resolved during the class init, and is now ready to call method with it.- Returns:
- true if this instance can be used to access sun.misc.Unsafe, false otherwise.
-
invokeMethod
public static @UnknownNullability Object invokeMethod(@NotNull @NotNull String methodName, @NotNull @NotNull Class<?>[] argTypes, @NotNull @NotNull Object... args) Calls the given method which is provided in sun.misc.Unsafe. This method returns null if either the method could not be resolved or the invocation throws an exception.- Parameters:
methodName- the name of the method to invoke.argTypes- the argument types of the method.args- the arguments to pass to the method.- Returns:
- the result of the method invocation.
- Throws:
NullPointerException- if the given method name, argument types or arguments array is null.IllegalStateException- if this util is not available for usage.
-