public class Hacks
extends java.lang.Object
| Constructor and Description |
|---|
Hacks() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
construct(java.lang.Class<?> target,
java.lang.Object... args)
Instantiates the target class using the given args
|
static <T> T |
construct(java.lang.Class<?> reference,
java.lang.String targetClass,
java.lang.Object... args)
Finds the target class via the reference class and instantiates it using the given args
|
static <T> T |
construct(java.lang.String targetClass,
java.lang.Object... args)
Finds and instantiates the target class using the given args
|
static <T> T |
constructDirect(java.lang.Class<?> target,
java.lang.Object... args)
Instantiates the target class using the given args
Constructing a class directly will bypass any package-private, private, or protected access restrictions.
|
static <T> T |
constructDirect(java.lang.Class<?> reference,
java.lang.String targetClass,
java.lang.Object... args)
Finds the target class via the reference class and instantiates it using the given args
Constructing a class directly will bypass any package-private, private, or protected access restrictions.
|
static <T> T |
constructDirect(java.lang.String targetClass,
java.lang.Object... args)
Finds and instantiates the target class using the given args
Constructing a class directly will bypass any package-private, private, or protected access restrictions.
|
static java.lang.ClassLoader |
contextClassLoader() |
static java.lang.Class<?> |
defaultCaller() |
static @Nullable java.lang.Class<?> |
findClass(@Nullable java.lang.Class<?> reference,
java.lang.String target)
Uses a reference class to find and return the target class in the same package as the reference class.
|
static @Nullable java.lang.Class<?> |
findClass(@Nullable java.lang.Package pkg,
java.lang.String target)
Find and return the target class in given package
|
static @Nullable java.lang.Class<?> |
findClass(java.lang.String target)
Finds and returns a Class object with the target name.
|
static @Nullable java.lang.Class<?> |
findClass(java.lang.String target,
boolean initialize)
Finds and returns a Class object with the target name using the given ClassLoader.
|
static @Nullable java.lang.Class<?> |
findClass(java.lang.String target,
java.lang.Class<?> caller)
Finds and returns a Class object with the target name using the given caller class.
|
static @Nullable java.lang.Class<?> |
findClass(java.lang.String target,
java.lang.Class<?> caller,
boolean initialize)
Finds and returns a Class object with the target name using the given caller class.
|
static @Nullable java.lang.Class<?> |
findClass(java.lang.String target,
java.lang.ClassLoader loader)
Finds and returns a Class object with the target name using the given ClassLoader.
|
static @Nullable java.lang.Class<?> |
findClass(java.lang.String target,
java.lang.ClassLoader loader,
boolean initialize)
Finds and returns a Class object with the target name using the given ClassLoader.
|
static @Nullable java.lang.Class<?> |
findClass(java.lang.String target,
java.lang.ClassLoader loader,
java.lang.Class<?> caller)
Finds and returns a Class object with the target name using the given ClassLoader and the given caller class.
|
static @Nullable java.lang.Class<?> |
findClass(java.lang.String target,
java.lang.ClassLoader loader,
java.lang.Class<?> caller,
boolean initialize)
Finds and returns a Class object with the target name using the given ClassLoader and the given caller class.
|
static @Nullable java.lang.Class<?> |
findClass(@Nullable java.lang.String pkg,
java.lang.String target)
Find and return the target class in given package name
|
static <T> T |
getField(java.lang.Object target,
java.lang.String field)
Returns a non-static field instance of the given name on the given object.
|
static <T> T |
getField(java.lang.Object target,
java.lang.String named,
java.lang.String intermediary)
Returns a non-static field instance of the given name on the given object.
|
static <T> T |
getFieldDirect(java.lang.Object target,
java.lang.String field)
Returns a non-static field instance of the given name on the given object.
|
static <T> T |
getFieldDirect(java.lang.Object target,
java.lang.String named,
java.lang.String intermediary)
Returns a non-static field instance of the given name on the given object.
|
static <T> T |
getFieldStatic(java.lang.Class<?> target,
java.lang.String field)
Returns a static field instance of the given name in the target class.
|
static <T> T |
getFieldStatic(java.lang.Class<?> target,
java.lang.String named,
java.lang.String intermediary)
Returns a static field instance of the given name in the target class.
|
static <T> T |
getFieldStatic(java.lang.String targetClass,
java.lang.String field)
Finds the target class and returns a static field instance of the given name in it.
|
static <T> T |
getFieldStatic(java.lang.String targetClass,
java.lang.String named,
java.lang.String intermediary)
Finds the target class and returns a static field instance of the given name in it.
|
static <T> T |
getFieldStaticDirect(java.lang.Class<?> target,
java.lang.String field)
Returns a static field instance of the given name in the target class.
|
static <T> T |
getFieldStaticDirect(java.lang.Class<?> target,
java.lang.String named,
java.lang.String intermediary)
Returns a static field instance of the given name in the target class.
|
static <T> T |
getFieldStaticDirect(java.lang.String targetClass,
java.lang.String field)
Finds the target class and returns a static field instance of the given name in it.
|
static <T> T |
getFieldStaticDirect(java.lang.String targetClass,
java.lang.String named,
java.lang.String intermediary)
Finds the target class and returns a static field instance of the given name in it.
|
static int |
getJavaVersion()
Returns the current Java version as an integer.
|
static <T> T |
getRecordField(java.lang.Object target,
java.lang.String field)
Returns the instance of a record field assuming the call is valid and the field exists.
|
static <T> T |
getRecordFieldStatic(java.lang.Class<?> target,
java.lang.String field)
Returns the instance of a static record field assuming the call is valid and the field exists.
|
static <T> T |
invoke(java.lang.Object target,
java.lang.String method,
java.lang.Object... args)
Invoke a non-static method of the given name on the given object with the given args.
|
static <T> T |
invoke(java.lang.Object target,
java.lang.String named,
java.lang.String intermediary,
java.lang.Object... args)
Invoke a non-static method of the given name on the given object with the given args.
|
static <T> T |
invokeDirect(java.lang.Object target,
java.lang.String method,
java.lang.Object... args)
Invoke a non-static method of the given name on the given object with the given args.
|
static <T> T |
invokeDirect(java.lang.Object target,
java.lang.String named,
java.lang.String intermediary,
java.lang.Object... args)
Invoke a non-static method of the given name on the given object with the given args.
|
static <T> T |
invokeStatic(java.lang.Class<?> target,
java.lang.String method,
java.lang.Object... args)
Invoke a static method of the given name in the target class with the given args.
|
static <T> T |
invokeStatic(java.lang.Class<?> target,
java.lang.String named,
java.lang.String intermediary,
java.lang.Object... args)
Invoke a static method of the given name in the target class with the given args.
|
static <T> T |
invokeStatic(java.lang.String targetClass,
java.lang.String method,
java.lang.Object... args)
Finds the target class and invokes a static method of the given name in it with the given args.
|
static <T> T |
invokeStatic(java.lang.String targetClass,
java.lang.String named,
java.lang.String intermediary,
java.lang.Object... args)
Finds the target class and invokes a static method of the given name in it with the given args.
|
static <T> T |
invokeStaticDirect(java.lang.Class<?> target,
java.lang.String method,
java.lang.Object... args)
Invoke a static method of the given name in the target class with the given args.
|
static <T> T |
invokeStaticDirect(java.lang.Class<?> target,
java.lang.String named,
java.lang.String intermediary,
java.lang.Object... args)
Invoke a static method of the given name in the target class with the given args.
|
static <T> T |
invokeStaticDirect(java.lang.String targetClass,
java.lang.String method,
java.lang.Object... args)
Finds the target class and invokes a static method of the given name in it with the given args.
|
static <T> T |
invokeStaticDirect(java.lang.String targetClass,
java.lang.String named,
java.lang.String intermediary,
java.lang.Object... args)
Finds the target class and invokes a static method of the given name in it with the given args.
|
static boolean |
isJava17()
Returns true if the Java version is 17
Java 17 is used from 1.18.2 to 1.20.4
|
static boolean |
isJava21()
Returns true if the Java version is AT LEAST 21.
|
static boolean |
isJava8()
Returns true if the Java version is 8
Java 8 is used in versions up to 1.16.5 except cleanroom for 1.12.2.
|
static boolean |
isNamedEnv()
Returns true if this is a named environment (for reflection purposes).
|
static boolean |
isSrgEnv()
Returns true if this is a srg environment (for reflection purposes).
|
public static <T> T construct(java.lang.String targetClass,
java.lang.Object... args)
public static <T> T construct(java.lang.Class<?> reference,
java.lang.String targetClass,
java.lang.Object... args)
public static <T> T construct(java.lang.Class<?> target,
java.lang.Object... args)
public static <T> T constructDirect(java.lang.String targetClass,
java.lang.Object... args)
public static <T> T constructDirect(java.lang.Class<?> reference,
java.lang.String targetClass,
java.lang.Object... args)
public static <T> T constructDirect(java.lang.Class<?> target,
java.lang.Object... args)
public static java.lang.ClassLoader contextClassLoader()
public static java.lang.Class<?> defaultCaller()
@Nullable
public static @Nullable java.lang.Class<?> findClass(java.lang.String target,
java.lang.ClassLoader loader,
java.lang.Class<?> caller,
boolean initialize)
@Nullable
public static @Nullable java.lang.Class<?> findClass(java.lang.String target,
java.lang.Class<?> caller,
boolean initialize)
@Nullable
public static @Nullable java.lang.Class<?> findClass(java.lang.String target,
java.lang.Class<?> caller)
@Nullable
public static @Nullable java.lang.Class<?> findClass(java.lang.String target,
java.lang.ClassLoader loader,
java.lang.Class<?> caller)
@Nullable
public static @Nullable java.lang.Class<?> findClass(java.lang.String target,
java.lang.ClassLoader loader,
boolean initialize)
@Nullable
public static @Nullable java.lang.Class<?> findClass(java.lang.String target,
java.lang.ClassLoader loader)
@Nullable
public static @Nullable java.lang.Class<?> findClass(java.lang.String target,
boolean initialize)
@Nullable public static @Nullable java.lang.Class<?> findClass(java.lang.String target)
@Nullable
public static @Nullable java.lang.Class<?> findClass(@Nullable
@Nullable java.lang.Class<?> reference,
java.lang.String target)
@Nullable
public static @Nullable java.lang.Class<?> findClass(@Nullable
@Nullable java.lang.Package pkg,
java.lang.String target)
@Nullable
public static @Nullable java.lang.Class<?> findClass(@Nullable
@Nullable java.lang.String pkg,
java.lang.String target)
public static <T> T getField(java.lang.Object target,
java.lang.String named,
java.lang.String intermediary)
public static <T> T getField(java.lang.Object target,
java.lang.String field)
public static <T> T getFieldDirect(java.lang.Object target,
java.lang.String named,
java.lang.String intermediary)
public static <T> T getFieldDirect(java.lang.Object target,
java.lang.String field)
public static <T> T getFieldStatic(java.lang.String targetClass,
java.lang.String named,
java.lang.String intermediary)
public static <T> T getFieldStatic(java.lang.Class<?> target,
java.lang.String named,
java.lang.String intermediary)
public static <T> T getFieldStatic(java.lang.String targetClass,
java.lang.String field)
public static <T> T getFieldStatic(java.lang.Class<?> target,
java.lang.String field)
public static <T> T getFieldStaticDirect(java.lang.String targetClass,
java.lang.String named,
java.lang.String intermediary)
public static <T> T getFieldStaticDirect(java.lang.Class<?> target,
java.lang.String named,
java.lang.String intermediary)
public static <T> T getFieldStaticDirect(java.lang.String targetClass,
java.lang.String field)
public static <T> T getFieldStaticDirect(java.lang.Class<?> target,
java.lang.String field)
public static int getJavaVersion()
public static <T> T getRecordField(java.lang.Object target,
java.lang.String field)
public static <T> T getRecordFieldStatic(java.lang.Class<?> target,
java.lang.String field)
public static <T> T invoke(java.lang.Object target,
java.lang.String named,
java.lang.String intermediary,
java.lang.Object... args)
public static <T> T invoke(java.lang.Object target,
java.lang.String method,
java.lang.Object... args)
public static <T> T invokeDirect(java.lang.Object target,
java.lang.String named,
java.lang.String intermediary,
java.lang.Object... args)
public static <T> T invokeDirect(java.lang.Object target,
java.lang.String method,
java.lang.Object... args)
public static <T> T invokeStatic(java.lang.String targetClass,
java.lang.String named,
java.lang.String intermediary,
java.lang.Object... args)
public static <T> T invokeStatic(java.lang.Class<?> target,
java.lang.String named,
java.lang.String intermediary,
java.lang.Object... args)
public static <T> T invokeStatic(java.lang.String targetClass,
java.lang.String method,
java.lang.Object... args)
public static <T> T invokeStatic(java.lang.Class<?> target,
java.lang.String method,
java.lang.Object... args)
public static <T> T invokeStaticDirect(java.lang.String targetClass,
java.lang.String named,
java.lang.String intermediary,
java.lang.Object... args)
public static <T> T invokeStaticDirect(java.lang.Class<?> target,
java.lang.String named,
java.lang.String intermediary,
java.lang.Object... args)
public static <T> T invokeStaticDirect(java.lang.String targetClass,
java.lang.String method,
java.lang.Object... args)
public static <T> T invokeStaticDirect(java.lang.Class<?> target,
java.lang.String method,
java.lang.Object... args)
public static boolean isJava8()
public static boolean isJava17()
public static boolean isJava21()
public static boolean isNamedEnv()
public static boolean isSrgEnv()