public class ClassHelper
extends java.lang.Object
类帮助器
一些操作类的方法
Class helper
Some methods that used to operate class
Email: fishinlove@163.com
created by 2019/03/28 22:31:45
| 构造器和说明 |
|---|
ClassHelper() |
| 限定符和类型 | 方法和说明 |
|---|---|
static java.lang.ClassLoader |
classLoaderOf(java.lang.Object obj)
获得这个对象的类加载器
实际上它就是在内部调用 classOf(obj).getClassLoader() 来获取类的类加载器的
这个方法的目的在于,提供更好的代码可读性和代码意义
Get the classloader of this object
In fact, it invokes classOf(obj).getClassLoader() to get what it needs
This method is to get more human-being and mean of the code
|
static java.lang.Class<?> |
classOf(java.lang.Object obj)
获得这个对象的类的类型
实际上它就是在内部调用 obj.getClass() 来获取类的类型的
这个方法的目的在于,提供更好的代码可读性和代码意义
Get the class of this object
In fact, it invokes obj.getClass() to get what it needs
This method is to get more human-being and mean of the code
|
static boolean |
hasInterface(java.lang.Object obj)
判断一个对象是否有实现接口
If target object has interface, return true
|
static java.lang.Class<?>[] |
interfacesOf(java.lang.Object obj)
获得这个对象实现的所有接口
实际上它就是在内部调用 classOf(obj).getInterfaces() 来获取类的所有接口的
这个方法的目的在于,提供更好的代码可读性和代码意义
Get the interfaces of this object
In fact, it invokes classOf(obj).getClassLoader() to get what it needs
This method is to get more human-being and mean of the code
|
static boolean |
isFinal(java.lang.Object obj) |
static java.lang.Object |
newInstance(java.lang.String className)
加载一个类,并返回一个实例化对象
Load a class, and return a instance of this class
|
static <T> T |
newInstance(java.lang.String className,
java.lang.Class<T> classType)
加载一个类,并返回一个实例化对象
出现异常就会返回 null
Load a class, and return a instance of this class
If exception happened, return null object
|
public static java.lang.Object newInstance(java.lang.String className)
throws java.lang.ClassNotFoundException,
java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException
加载一个类,并返回一个实例化对象
Load a class, and return a instance of this class
className - 要被加载的类名
Name of loaded class
返回这个被加载类的实例对象
Return the instance of loaded class
java.lang.ClassNotFoundException - 如果找不到这个类
If the class is not found
java.lang.IllegalAccessException - 如果这个类不允许访问
If the class is not allowed to access
java.lang.InstantiationException - 如果这个类没有默认构造函数
If the class do not has default constructor
java.lang.NoSuchMethodException - 如果这个类没有默认构造函数
If the class do not has default constructor
java.lang.reflect.InvocationTargetException - 如果这个类不允许访问
If the class is not allowed to access
public static <T> T newInstance(java.lang.String className,
java.lang.Class<T> classType)
加载一个类,并返回一个实例化对象
出现异常就会返回 null
Load a class, and return a instance of this class
If exception happened, return null object
T - 实际类型
Real type
className - 要被加载的类名
Name of loaded class
classType - 类的实际类型,用于类型转换
The type of class, used to cast
返回这个被加载类的实例对象
Return the instance of loaded class
public static java.lang.Class<?> classOf(java.lang.Object obj)
获得这个对象的类的类型
实际上它就是在内部调用 obj.getClass() 来获取类的类型的
这个方法的目的在于,提供更好的代码可读性和代码意义
Get the class of this object
In fact, it invokes obj.getClass() to get what it needs
This method is to get more human-being and mean of the code
obj - 想获得 class 的对象
The target object
返回这个对象的类的类型
Return the class of this object
Object.getClass()public static java.lang.ClassLoader classLoaderOf(java.lang.Object obj)
获得这个对象的类加载器
实际上它就是在内部调用 classOf(obj).getClassLoader() 来获取类的类加载器的
这个方法的目的在于,提供更好的代码可读性和代码意义
Get the classloader of this object
In fact, it invokes classOf(obj).getClassLoader() to get what it needs
This method is to get more human-being and mean of the code
obj - 想获得类加载器的对象
The target object
返回这个对象的类加载器
Return the classloader of this object
Class.getClassLoader(),
classOf(java.lang.Object)public static java.lang.Class<?>[] interfacesOf(java.lang.Object obj)
获得这个对象实现的所有接口
实际上它就是在内部调用 classOf(obj).getInterfaces() 来获取类的所有接口的
这个方法的目的在于,提供更好的代码可读性和代码意义
Get the interfaces of this object
In fact, it invokes classOf(obj).getClassLoader() to get what it needs
This method is to get more human-being and mean of the code
obj - 想获得实现的所有接口的对象
The target object
返回这个对象实现的所有接口
Return the interfaces of this object
Class.getInterfaces(),
classOf(java.lang.Object)public static boolean hasInterface(java.lang.Object obj)
判断一个对象是否有实现接口
If target object has interface, return true
obj - 被判断的对象
The target object
true 如果有实现接口,反之 false
true if target has interfaces, false if not
public static boolean isFinal(java.lang.Object obj)
Copyright © 2019. All Rights Reserved.