- java.lang.Object
- 
- cn.mcres.karlatemp.mxlib.tools.Toolkit.Reflection
 
- 
- 
字段概要字段 修饰符和类型 字段 说明 static intLOAD_CLASS_CALLER_CLASSLOADERstatic intLOAD_CLASS_THREAD_CONTENT
 - 
构造器概要构造器 构造器 说明 Reflection()
 - 
方法概要修饰符和类型 方法 说明 static <T> TallocObject(Class<T> type)static <T> Tclone(T object)Clone a object.static voidcopyValues(Object from, Object to)static Class<?>defineClass(ClassLoader loader, @org.jetbrains.annotations.NotNull byte[] code, ProtectionDomain protectionDomain)The first class defined in a package determines the exact set of certificates that all subsequent classes defined in that package must contain.static Class<?>defineClass(ClassLoader loader, @NotNull org.objectweb.asm.ClassWriter code, ProtectionDomain protectionDomain)The first class defined in a package determines the exact set of certificates that all subsequent classes defined in that package must contain.static Class<?>defineClass(ClassLoader loader, String name, @org.jetbrains.annotations.NotNull byte[] b, int off, int len, ProtectionDomain protectionDomain)The first class defined in a package determines the exact set of certificates that all subsequent classes defined in that package must contain.static Class<?>defineClass(ClassLoader loader, String name, @org.jetbrains.annotations.NotNull byte[] code, ProtectionDomain protectionDomain)The first class defined in a package determines the exact set of certificates that all subsequent classes defined in that package must contain.static Class<?>forName(String name, boolean initialize, ClassLoader loader)Returns theClassobject associated with the class or interface with the given string name, using the given class loader.static @NotNull Class<?>getCallerClass()获取调用者的Classstatic @Nullable Class<?>getCallerClass(int point)获取调用者的Classstatic ClassLoadergetClassLoader(Class<?> clazz)static Toolkit.ReflectiongetInstance()这只能用来判断使用哪种方法Object.getClass()static ObjectgetObjectValue(Object this_, @NotNull Field field)Get field value with Unsafestatic MethodHandles.LookupgetRoot()获取最高权限的Lookupstatic Class<?>loadClassFrom(String name, @NotNull Collection<ClassLoader> loaders)Load class from class loadersstatic Class<?>loadClassLink(Collection<String> types, @Nullable ClassLoader loader)static @Nullable Class<?>loadClassWith(String name, int flags)Load class from class loadersstatic <T extends AccessibleObject>
 TsetAccess(T accessibleObject, boolean b)static voidsetObjectValue(Object this_, @NotNull Field field, Object value)Change object's field value.
 
- 
- 
- 
方法详细资料- 
getInstance@Contract(pure=true) public static Toolkit.Reflection getInstance() 这只能用来判断使用哪种方法Object.getClass()- 返回:
- 使用的实例
 
 - 
getRoot@Contract(pure=true) public static MethodHandles.Lookup getRoot() 获取最高权限的Lookup- 返回:
- 最高权限的Lookup
 
 - 
forNamepublic static Class<?> forName(String name, boolean initialize, ClassLoader loader) Returns theClassobject associated with the class or interface with the given string name, using the given class loader. Given the fully qualified name for a class or interface (in the same format returned bygetName) this method attempts to locate, load, and link the class or interface. The specified class loader is used to load the class or interface. If the parameterloaderis null, the class is loaded through the bootstrap class loader. The class is initialized only if theinitializeparameter istrueand if it has not been initialized earlier.If namedenotes a primitive type or void, an attempt will be made to locate a user-defined class in the unnamed package whose name isname. Therefore, this method cannot be used to obtain any of theClassobjects representing primitive types or void.If namedenotes an array class, the component type of the array class is loaded but not initialized.For example, in an instance method the expression: Class.forName("Foo")is equivalent to: Class.forName("Foo", true, this.getClass().getClassLoader())Note that this method throws errors related to loading, linking or initializing as specified in Sections 12.2, 12.3 and 12.4 of The Java Language Specification. Note that this method does not check whether the requested class is accessible to its caller. - 参数:
- name- fully qualified name of the desired class
- initialize- if- truethe class will be initialized. See Section 12.4 of The Java Language Specification.
- loader- class loader from which the class must be loaded
- 返回:
- class object representing the desired class
- 抛出:
- LinkageError- if the linkage fails
- ExceptionInInitializerError- if the initialization provoked by this method fails
- NoClassDefFoundError- if the class cannot be located by the specified class loader
- SecurityException- if a security manager is present, and the- loaderis- null, and the caller's class loader is not- null, and the caller does not have the- RuntimePermission- ("getClassLoader")
- 从以下版本开始:
- 1.2
- 另请参阅:
- Class.forName(String),- Class.forName(String, boolean, ClassLoader),- ClassLoader
 
 - 
loadClassWith@Contract("null,_ -> null; !null, _ -> !null") @Nullable public static @Nullable Class<?> loadClassWith(String name, int flags) throws ClassNotFoundExceptionLoad class from class loaders- 参数:
- name- The class name
- flags- Loading flags
- 返回:
- The class loaded
- 抛出:
- ClassNotFoundException- If class not found
- 从以下版本开始:
- 2.2
 
 - 
loadClassFrom@Contract("null,_ -> null;!null,_ -> !null") public static Class<?> loadClassFrom(String name, @NotNull @NotNull Collection<ClassLoader> loaders) throws ClassNotFoundExceptionLoad class from class loaders- 参数:
- name- The name of class
- loaders- Loaders
- 返回:
- The class loaded
- 抛出:
- ClassNotFoundException- If class not found in any loader
- 从以下版本开始:
- 2.2
 
 - 
loadClassLinkpublic static Class<?> loadClassLink(Collection<String> types, @Nullable @Nullable ClassLoader loader) throws ClassNotFoundException 
 - 
setAccess@Contract("null, _ -> null; !null, _ -> !null") public static <T extends AccessibleObject> T setAccess(T accessibleObject, boolean b)
 - 
allocObjectpublic static <T> T allocObject(Class<T> type) 
 - 
defineClasspublic static Class<?> defineClass(ClassLoader loader, String name, @NotNull @org.jetbrains.annotations.NotNull byte[] b, int off, int len, ProtectionDomain protectionDomain) throws ClassFormatError The first class defined in a package determines the exact set of certificates that all subsequent classes defined in that package must contain. The set of certificates for a class is obtained from the CodeSourcewithin the ProtectionDomain of the class. Any classes added to that package must contain the same set of certificates or a SecurityException will be thrown. Note that if name is null, this check is not performed. You should always pass in the binary name of the class you are defining as well as the bytes. This ensures that the class you are defining is indeed the class you think it is.The specified name cannot begin with "java.", since all classes in the "java.* packages can only be defined by the bootstrap class loader. If name is not null, it must be equal to the binary name of the class specified by the byte array "b", otherwise a NoClassDefFoundErrorwill be thrown.- 参数:
- loader- The loader to be executed
- name- The expected binary name of the class, or null if not known
- b- The bytes that make up the class data. The bytes in positions off through off+len-1 should have the format of a valid class file as defined by The Java™ Virtual Machine Specification.
- off- The start offset in b of the class data
- len- The length of the class data
- protectionDomain- The ProtectionDomain of the class
- 返回:
- The Class object created from the data, and optional ProtectionDomain.
- 抛出:
- ClassFormatError- If the data did not contain a valid class
- NoClassDefFoundError- If name is not equal to the binary name of the class specified by b
- IndexOutOfBoundsException- If either off or len is negative, or if off+len is greater than b.length.
- SecurityException- If an attempt is made to add this class to a package that contains classes that were signed by a different set of certificates than this class, or if name begins with "java.".
 
 - 
defineClasspublic static Class<?> defineClass(ClassLoader loader, String name, @NotNull @org.jetbrains.annotations.NotNull byte[] code, ProtectionDomain protectionDomain) throws ClassFormatError The first class defined in a package determines the exact set of certificates that all subsequent classes defined in that package must contain. The set of certificates for a class is obtained from the CodeSourcewithin the ProtectionDomain of the class. Any classes added to that package must contain the same set of certificates or a SecurityException will be thrown. Note that if name is null, this check is not performed. You should always pass in the binary name of the class you are defining as well as the bytes. This ensures that the class you are defining is indeed the class you think it is.The specified name cannot begin with "java.", since all classes in the "java.* packages can only be defined by the bootstrap class loader. If name is not null, it must be equal to the binary name of the class specified by the byte array "b", otherwise a NoClassDefFoundErrorwill be thrown.- 参数:
- loader- The loader to be executed
- name- The expected binary name of the class, or null if not known
- code- The bytes that make up the class data. The bytes in positions off through off+len-1 should have the format of a valid class file as defined by The Java™ Virtual Machine Specification.
- protectionDomain- The ProtectionDomain of the class
- 返回:
- The Class object created from the data, and optional ProtectionDomain.
- 抛出:
- ClassFormatError- If the data did not contain a valid class
- NoClassDefFoundError- If name is not equal to the binary name of the class specified by code
- SecurityException- If an attempt is made to add this class to a package that contains classes that were signed by a different set of certificates than this class, or if name begins with "java.".
- 从以下版本开始:
- 2.11
 
 - 
defineClasspublic static Class<?> defineClass(ClassLoader loader, @NotNull @org.jetbrains.annotations.NotNull byte[] code, ProtectionDomain protectionDomain) throws ClassFormatError The first class defined in a package determines the exact set of certificates that all subsequent classes defined in that package must contain. The set of certificates for a class is obtained from the CodeSourcewithin the ProtectionDomain of the class. Any classes added to that package must contain the same set of certificates or a SecurityException will be thrown. Note that if name is null, this check is not performed. You should always pass in the binary name of the class you are defining as well as the bytes. This ensures that the class you are defining is indeed the class you think it is.The specified name cannot begin with "java.", since all classes in the "java.* packages can only be defined by the bootstrap class loader. If name is not null, it must be equal to the binary name of the class specified by the byte array "b", otherwise a NoClassDefFoundErrorwill be thrown.- 参数:
- loader- The loader to be executed
- code- The bytes that make up the class data. The bytes in positions off through off+len-1 should have the format of a valid class file as defined by The Java™ Virtual Machine Specification.
- protectionDomain- The ProtectionDomain of the class
- 返回:
- The Class object created from the data, and optional ProtectionDomain.
- 抛出:
- ClassFormatError- If the data did not contain a valid class
- NoClassDefFoundError- If name is not equal to the binary name of the class specified by b
- SecurityException- If an attempt is made to add this class to a package that contains classes that were signed by a different set of certificates than this class, or if name begins with "java.".
- 从以下版本开始:
- 2.11
 
 - 
defineClasspublic static Class<?> defineClass(ClassLoader loader, @NotNull @NotNull org.objectweb.asm.ClassWriter code, ProtectionDomain protectionDomain) throws ClassFormatError The first class defined in a package determines the exact set of certificates that all subsequent classes defined in that package must contain. The set of certificates for a class is obtained from the CodeSourcewithin the ProtectionDomain of the class. Any classes added to that package must contain the same set of certificates or a SecurityException will be thrown. Note that if name is null, this check is not performed. You should always pass in the binary name of the class you are defining as well as the bytes. This ensures that the class you are defining is indeed the class you think it is.The specified name cannot begin with "java.", since all classes in the "java.* packages can only be defined by the bootstrap class loader. If name is not null, it must be equal to the binary name of the class specified by the byte array "b", otherwise a NoClassDefFoundErrorwill be thrown.- 参数:
- loader- The loader to be executed
- code- The bytes that make up the class data. The bytes in positions off through off+len-1 should have the format of a valid class file as defined by The Java™ Virtual Machine Specification.
- protectionDomain- The ProtectionDomain of the class
- 返回:
- The Class object created from the data, and optional ProtectionDomain.
- 抛出:
- ClassFormatError- If the data did not contain a valid class
- NoClassDefFoundError- If name is not equal to the binary name of the class specified by b
- SecurityException- If an attempt is made to add this class to a package that contains classes that were signed by a different set of certificates than this class, or if name begins with "java.".
- 从以下版本开始:
- 2.11
 
 - 
getCallerClass@NotNull @Contract(pure=true) public static @NotNull Class<?> getCallerClass() 获取调用者的Class- 返回:
- 获取调用者的Class
- 抛出:
- ArrayIndexOutOfBoundsException- 在程序main入口调用时抛出
 
 - 
getCallerClass@Nullable @Contract(pure=true) public static @Nullable Class<?> getCallerClass(int point) 获取调用者的Class- 参数:
- point- 指定的堆栈位置
- 返回:
- 获取调用者的Class
 
 - 
clone@Contract(pure=true, value="null -> null; !null -> !null") public static <T> T clone(T object)Clone a object.- 类型参数:
- T- The type of object
- 参数:
- object- The source object
- 返回:
- the cloned object
- 从以下版本开始:
- 2.7
 
 - 
getObjectValuepublic static Object getObjectValue(Object this_, @NotNull @NotNull Field field) Get field value with Unsafe- 参数:
- this_- The this object of field.
- field- The field of object.
- 返回:
- The field value.
- 从以下版本开始:
- 2.7
 
 - 
setObjectValuepublic static void setObjectValue(Object this_, @NotNull @NotNull Field field, Object value) Change object's field value.- 参数:
- this_- The this variable.
- field- The field need change.
- value- The value override.
 
 - 
getClassLoader@Contract(pure=true, value="null -> fail;") public static ClassLoader getClassLoader(Class<?> clazz)
 
- 
 
-