Java Reference
In-Depth Information
The Class class provides a toString method, but it already adds "class"
or "interface" in front. We want to control the prefix, so we must create
our own implementation. We look more at class names a little later.
Next, the type is examined to see if it is a generic type. All classes imple-
ment GenericDeclaration , which defines the single method getTypePara-
meters that returns an array of TypeVariable objects. If we have one or
more type parameters then we print each of their names between angle
brackets, just as they would appear in your source code.
After printing the type description, printType invokes itself recursively,
first on all the interfaces that the original type implements and then
on the superclass this type extends (if any), passing the appropriate
label array to each. Eventually, it reaches the Class object for Object ,
which implements no interfaces and whose getGenericSuperclass method
returns null , and the recursion ends.
Some simple query methods, a few of which you saw in the example,
examine the kind of Class object that you are dealing with:
public boolean isEnum()
Returns true if this Class object represents an enum.
public boolean isInterface()
Returns true if this Class object represents an interface (which
includes annotation types).
public boolean isAnnotation()
Returns true if this Class object represents an annotation type.
public boolean isArray()
Returns TRue if this Class object represents an array.
 
Search WWH ::




Custom Search