com.alibaba.dubbo.common.utils
Class ClassHelper

java.lang.Object
  extended by com.alibaba.dubbo.common.utils.ClassHelper

public class ClassHelper
extends Object


Field Summary
static String ARRAY_SUFFIX
          Suffix for array class names: "[]"
 
Constructor Summary
ClassHelper()
           
 
Method Summary
static Class<?> forName(String name)
          Same as Class.forName(), except that it works for primitive types.
static Class<?> forName(String name, ClassLoader classLoader)
          Replacement for Class.forName() that also returns Class instances for primitives (like "int") and array class names (like "String[]").
static Class<?> forNameWithCallerClassLoader(String name, Class<?> caller)
           
static Class<?> forNameWithThreadContextClassLoader(String name)
           
static ClassLoader getCallerClassLoader(Class<?> caller)
           
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.
static ClassLoader getClassLoader(Class<?> cls)
          get class loader
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.
static String toShortString(Object obj)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARRAY_SUFFIX

public static final String ARRAY_SUFFIX
Suffix for array class names: "[]"

See Also:
Constant Field Values
Constructor Detail

ClassHelper

public ClassHelper()
Method Detail

forNameWithThreadContextClassLoader

public static Class<?> forNameWithThreadContextClassLoader(String name)
                                                    throws ClassNotFoundException
Throws:
ClassNotFoundException

forNameWithCallerClassLoader

public static Class<?> forNameWithCallerClassLoader(String name,
                                                    Class<?> caller)
                                             throws ClassNotFoundException
Throws:
ClassNotFoundException

getCallerClassLoader

public static ClassLoader getCallerClassLoader(Class<?> caller)

getClassLoader

public static ClassLoader getClassLoader(Class<?> cls)
get class loader

Parameters:
cls -
Returns:
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).

Returns:
the default ClassLoader (never null)
See Also:
Thread.getContextClassLoader()

forName

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

Throws:
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[]").

Parameters:
name - the name of the Class
classLoader - the class loader to use (may be null, which indicates the default class loader)
Returns:
Class instance for the supplied name
Throws:
ClassNotFoundException - if the class was not found
LinkageError - if the class file could not be loaded
See Also:
Class.forName(String, boolean, ClassLoader)

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).

Parameters:
name - the name of the potentially primitive class
Returns:
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)


Copyright © 2012–2017 Alibaba. All rights reserved.