类 ClassHelper

java.lang.Object
com.baidu.bjf.remoting.protobuf.utils.ClassHelper

public class ClassHelper extends Object
A utility class for class and class loader.
从以下版本开始:
1.0.0
作者:
xiemalin
  • 字段详细资料

    • PACKAGE_SEPARATOR_CHAR

      public static final char PACKAGE_SEPARATOR_CHAR
      package separator char
      另请参阅:
    • PACKAGE_SEPARATOR

      public static final String PACKAGE_SEPARATOR
      package separator string
      另请参阅:
    • ARRAY_SUFFIX

      public static final String ARRAY_SUFFIX
      Suffix for array class names: "[]"
      另请参阅:
  • 构造器详细资料

    • ClassHelper

      public ClassHelper()
  • 方法详细资料

    • getInternalName

      public static String getInternalName(String clsName)
      get class internal name from Class.getName(). sub class like A$B to A.B
      参数:
      clsName - class name
      返回:
      internalname
    • getLastModifyTime

      public static long getLastModifyTime(Class<?> cls)
    • 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 name
      caller - caller of Class type
      返回:
      loaded class
      抛出:
      ClassNotFoundException - if class not found
    • getCallerClassLoader

      public static ClassLoader getCallerClassLoader(Class<?> caller)
      get class loader from caller calss
      参数:
      caller - caller of Class type
      返回:
      loaded class loader
    • getClassLoader

      public static ClassLoader getClassLoader(Class<?> cls)
      get class loader
      参数:
      cls - target class to get ownered class loader
      返回:
      class loader
    • getClassLoader

      public static ClassLoader 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 a null ClassLoader reference as well).

      返回:
      the default ClassLoader (never null)
      另请参阅:
    • forName

      public static Class<?> forName(String name) throws ClassNotFoundException
      Same as Class.forName(), except that it works for primitive types.
      抛出:
      ClassNotFoundException
    • forName

      public static Class<?> forName(String name, ClassLoader classLoader) throws ClassNotFoundException, LinkageError
      Replacement for Class.forName() that also returns Class instances for primitives (like "int") and array class names (like "String[]").
      参数:
      name - the name of the Class
      classLoader - the class loader to use (may be null, which indicates the default class loader)
      返回:
      Class instance for the supplied name
      抛出:
      ClassNotFoundException - if the class was not found
      LinkageError - if the class file could not be loaded
      另请参阅:
    • resolvePrimitiveClassName

      public static Class<?> resolvePrimitiveClassName(String name)
      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 null if the name does not denote a primitive class or primitive array class
    • toShortString

      public static String toShortString(Object obj)
      To get short message of object instance.
      参数:
      obj - target object
      返回:
      short message
    • getClassName

      public static String getClassName(Class<?> cls)
      get class simple name from Class instance.
      Here we should take case member class is a little different from common class.
      参数:
      cls - target class
      返回:
      simple class name
    • getPackage

      public static String getPackage(Class<?> cls)
    • hasDefaultConstructor

      public static boolean hasDefaultConstructor(Class<?> cls)
      To test class if has default constructor method
      参数:
      cls - target class
      返回:
      true if has default constructor method
    • getFullClassName

      public static String getFullClassName(Class<?> cls)
      get new class name with full package
      返回:
      class name