public class ClassUtils extends Object
Operates on classes without using reflection.
This class handles invalid null
inputs as best it can.
Each method documents its behaviour in more detail.
The notion of a canonical name
includes the human
readable name for the type, for example int[]
. The
non-canonical method variants work with the JVM names, such as
[I
.
Modifier and Type | Field and Description |
---|---|
static String |
INNER_CLASS_SEPARATOR
The inner class separator String:
"$" . |
static char |
INNER_CLASS_SEPARATOR_CHAR
The inner class separator character:
'$' == 36 . |
static String |
PACKAGE_SEPARATOR
The package separator String:
"." . |
static char |
PACKAGE_SEPARATOR_CHAR
The package separator character:
'.' == 46 . |
Constructor and Description |
---|
ClassUtils()
ClassUtils instances should NOT be constructed in standard programming.
|
Modifier and Type | Method and Description |
---|---|
static String |
getPackageName(Class cls)
Gets the package name of a
Class . |
static String |
getPackageName(Object object,
String valueIfNull)
Gets the package name of an
Object . |
static String |
getPackageName(String className)
Gets the package name from a
String . |
static String |
getShortClassName(Class cls)
Gets the class name minus the package name from a
Class . |
static String |
getShortClassName(Object object,
String valueIfNull)
Gets the class name minus the package name for an
Object . |
static String |
getShortClassName(String className)
Gets the class name minus the package name from a String.
|
public static final char PACKAGE_SEPARATOR_CHAR
The package separator character: '.' == 46
.
public static final String PACKAGE_SEPARATOR
The package separator String: "."
.
public static final char INNER_CLASS_SEPARATOR_CHAR
The inner class separator character: '$' == 36
.
public static final String INNER_CLASS_SEPARATOR
The inner class separator String: "$"
.
public ClassUtils()
ClassUtils instances should NOT be constructed in standard programming.
Instead, the class should be used as
ClassUtils.getShortClassName(cls)
.
This constructor is public to permit tools that require a JavaBean instance to operate.
public static String getShortClassName(Object object, String valueIfNull)
Gets the class name minus the package name for an Object
.
object
- the class to get the short name for, may be nullvalueIfNull
- the value to return if nullpublic static String getShortClassName(Class cls)
Gets the class name minus the package name from a Class
.
cls
- the class to get the short name for.public static String getShortClassName(String className)
Gets the class name minus the package name from a String.
The string passed in is assumed to be a class name - it is not checked.
className
- the className to get the short name forpublic static String getPackageName(Object object, String valueIfNull)
Gets the package name of an Object
.
object
- the class to get the package name for, may be nullvalueIfNull
- the value to return if nullpublic static String getPackageName(Class cls)
Gets the package name of a Class
.
cls
- the class to get the package name for, may be null
.public static String getPackageName(String className)
Gets the package name from a String
.
The string passed in is assumed to be a class name - it is not checked.
If the class is unpackaged, return an empty string.
className
- the className to get the package name for, may be null