类 ClassHelper
java.lang.Object
com.baidu.bjf.remoting.protobuf.utils.ClassHelper
A utility class for class and class loader.
- 从以下版本开始:
- 1.0.0
- 作者:
- xiemalin
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static Class<?>Same asClass.forName(), except that it works for primitive types.static Class<?>forName(String name, ClassLoader classLoader) Replacement forClass.forName()that also returns Class instances for primitives (like "int") and array class names (like "String[]").static Class<?>forNameWithCallerClassLoader(String name, Class<?> caller) to initialize clss by name from caller.static Class<?>To fix name with thread context of class loaderstatic ClassLoadergetCallerClassLoader(Class<?> caller) get class loader from caller calssstatic ClassLoaderReturn the default ClassLoader to use: typically the thread context ClassLoader, if available; the ClassLoader that loaded the ClassUtils class will be used as fallback.static ClassLoadergetClassLoader(Class<?> cls) get class loaderstatic StringgetClassName(Class<?> cls) get class simple name fromClassinstance.static StringgetFullClassName(Class<?> cls) get new class name with full packagestatic StringgetInternalName(String clsName) get class internal name from Class.getName(). sub class like A$B to A.Bstatic longgetLastModifyTime(Class<?> cls) static StringgetPackage(Class<?> cls) static booleanhasDefaultConstructor(Class<?> cls) To test class if has default constructor methodstatic Class<?>Resolve the given class name as primitive class, if appropriate, according to the JVM's naming rules for primitive classes.static StringtoShortString(Object obj) To get short message of object instance.
-
字段详细资料
-
构造器详细资料
-
ClassHelper
public ClassHelper()
-
-
方法详细资料
-
getInternalName
get class internal name from Class.getName(). sub class like A$B to A.B- 参数:
clsName- class name- 返回:
- internalname
-
getLastModifyTime
-
forNameWithThreadContextClassLoader
public static Class<?> forNameWithThreadContextClassLoader(String name) throws ClassNotFoundException To fix name with thread context of class loader- 参数:
name- class name- 返回:
- loaded class
- 抛出:
ClassNotFoundException- if class not found
-
forNameWithCallerClassLoader
public static Class<?> forNameWithCallerClassLoader(String name, Class<?> caller) throws ClassNotFoundException to initialize clss by name from caller.- 参数:
name- class namecaller- caller of Class type- 返回:
- loaded class
- 抛出:
ClassNotFoundException- if class not found
-
getCallerClassLoader
get class loader from caller calss- 参数:
caller- caller of Class type- 返回:
- loaded class loader
-
getClassLoader
get class loader- 参数:
cls- target class to get ownered class loader- 返回:
- class loader
-
getClassLoader
Return the default ClassLoader to use: typically the thread context ClassLoader, if available; the ClassLoader that loaded the ClassUtils class will be used as fallback.Call this method if you intend to use the thread context ClassLoader in a scenario where you absolutely need a non-null ClassLoader reference: for example, for class path resource loading (but not necessarily for
Class.forName, which accepts anullClassLoader reference as well).- 返回:
- the default ClassLoader (never
null) - 另请参阅:
-
forName
Same asClass.forName(), except that it works for primitive types. -
forName
public static Class<?> forName(String name, ClassLoader classLoader) throws ClassNotFoundException, LinkageError Replacement forClass.forName()that also returns Class instances for primitives (like "int") and array class names (like "String[]").- 参数:
name- the name of the ClassclassLoader- the class loader to use (may benull, which indicates the default class loader)- 返回:
- Class instance for the supplied name
- 抛出:
ClassNotFoundException- if the class was not foundLinkageError- if the class file could not be loaded- 另请参阅:
-
resolvePrimitiveClassName
Resolve the given class name as primitive class, if appropriate, according to the JVM's naming rules for primitive classes.Also supports the JVM's internal class names for primitive arrays. Does not support the "[]" suffix notation for primitive arrays; this is only supported by
forName(java.lang.String).- 参数:
name- the name of the potentially primitive class- 返回:
- the primitive class, or
nullif the name does not denote a primitive class or primitive array class
-
toShortString
To get short message of object instance.- 参数:
obj- target object- 返回:
- short message
-
getClassName
get class simple name fromClassinstance.
Here we should take case member class is a little different from common class.- 参数:
cls- target class- 返回:
- simple class name
-
getPackage
-
hasDefaultConstructor
To test class if has default constructor method- 参数:
cls- target class- 返回:
- true if has default constructor method
-
getFullClassName
get new class name with full package- 返回:
- class name
-