类 DefineClassHelper
java.lang.Object
cn.taketoday.util.DefineClassHelper
Helper class for invoking
ClassLoader.defineClass(String, byte[], int, int).- 从以下版本开始:
- 4.0
- 作者:
- TODAY 2021/11/8 9:44
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static Class<?>defineClass(Class<?> neighbor, byte[] bcode) Loads a class file byjava.lang.invoke.MethodHandles.Lookup.static Class<?>defineClass(String className, byte[] b, ClassLoader loader) static Class<?>defineClass(String className, byte[] b, ClassLoader loader, ProtectionDomain protectionDomain) static Class<?>defineClass(String className, Class<?> neighbor, ClassLoader loader, ProtectionDomain domain, byte[] classFile) Loads a class file by a given class loader.
-
构造器详细资料
-
DefineClassHelper
public DefineClassHelper()
-
-
方法详细资料
-
defineClass
Loads a class file byjava.lang.invoke.MethodHandles.Lookup. It is obtained by usingneighbor.- 参数:
neighbor- a class belonging to the same package that the loaded class belogns to.bcode- the bytecode.- 抛出:
ReflectionException
-
defineClass
public static Class<?> defineClass(String className, byte[] b, ClassLoader loader) throws CodeGenerationException -
defineClass
public static Class<?> defineClass(String className, byte[] b, ClassLoader loader, ProtectionDomain protectionDomain) throws CodeGenerationException -
defineClass
public static Class<?> defineClass(String className, @Nullable Class<?> neighbor, ClassLoader loader, @Nullable ProtectionDomain domain, byte[] classFile) throws CodeGenerationException Loads a class file by a given class loader.This first tries to use
java.lang.invoke.MethodHandleto load a class. Otherwise, or ifneighboris null, this tries to usesun.misc.Unsafeto load a class. Then it tries to use aprotectedmethod injava.lang.ClassLoaderviaPrivilegedAction. Since the latter approach is not available any longer by default in Java 9 or later, the JVM argument--add-opens java.base/java.lang=ALL-UNNAMEDmust be given to the JVM.--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED
- 参数:
className- the name of the loaded class.neighbor- the class contained in the same package as the loaded class.loader- the class loader. It can be null ifneighboris not null and the JVM is Java 11 or later.domain- if it is null, a default domain is used.classFile- the bytecode for the loaded class.- 抛出:
CodeGenerationException
-