public final class ClassName extends Object implements Comparable<ClassName>, Comparator<ClassName>, Serializable
Warning: The same reference is often returned by the getClassName factory method for multiple calls which use the same type name as its parameter. However, no guarantee is made that this behavior will always be true, so the equals method should always be used to compare ClassName instances.
Modifier and Type | Method and Description |
---|---|
int |
compare(ClassName o1,
ClassName o2)
Compares its two arguments for order.
|
int |
compareTo(ClassName obj)
Compares this ClassName to another Object.
|
boolean |
equals(Object obj) |
static ClassName |
getClassName(String classType)
Returns the ClassName object referenced by a class
type string (field descriptor), as defined in the
JVM Specification, sections 4.3.2 and 4.2.
|
String |
getExternalName()
Returns the "external" classname, as defined by the
Java Language Specification, without any parameter
or return type information.
|
String |
getExternalName(boolean suppressArrays)
Returns the "external" classname, as defined by the
Java Language Specification, without any parameter
or return type information.
|
String |
getInternalName()
Returns the "internal" classname, as defined by the JVM
Specification, without any parameter or return type
information.
|
String |
getPackage()
Return the package portion of this classname.
|
String |
getSimpleName()
Returns the classname without any package specification.
|
String |
getType()
Returns the type string of this class, as stored in the
classfile (it's "raw" form).
|
int |
hashCode() |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
public static ClassName getClassName(String classType)
Basically, the JVM Specification defines a class type string where the periods ('.') separating a package name are replaced by forward slashes ('/'). Not documented in the second edition of the specification is that periods separating inner and outer classes are replaced with dollar signs ('$'). Array classes have one or more left brackets ('[') prepending the class type. For example:
java.lang.String java/lang/String java.util.HashMap.Entry java/util/HashMap$Entry java.lang.Integer[] [java/lang/Integer java.awt.Point[][] [[java/awt/Point
This method also accepts type strings which contain with 'L' and end with ';' characters. This format is used to reference a class in other type names, such as method arguments. These two characters are removed from the type string.
Because ClassNames are immutable, multiple requests to get the same type string may return identical object references. This cannot be assumed, however, and the ClassName.equals() method should be used instead of "==" to test for equality.
classType
- the class type string, as defined by the JVM spec.IllegalArgumentException
- if classType isn't of the correct
format.public String getType()
public String getInternalName()
public String getExternalName()
public String getExternalName(boolean suppressArrays)
suppressArrays
- true if array characters should be includedpublic String getPackage()
public String getSimpleName()
public boolean equals(Object obj)
equals
in interface Comparator<ClassName>
equals
in class Object
public int compareTo(ClassName obj)
ClassCastException
.compareTo
in interface Comparable<ClassName>
obj
- the Object
to be compared.0
if the argument is a string
lexicographically equal to this string; a value less than
0
if the argument is a string lexicographically
greater than this string; and a value greater than
0
if the argument is a string lexicographically
less than this string.Comparable
public int compare(ClassName o1, ClassName o2)
compare
in interface Comparator<ClassName>
o1
- the first object to be compared.o2
- the second object to be compared.ClassCastException
- if the arguments' types prevent them from
being compared by this Comparator.