Java Reference
In-Depth Information
}
// ... definition of strip ...
}
We first get the Class object for the named class. We then get and
print the arrays of member objects that represent all the public fields,
constructors, and methods of the class. The printMembers method uses
the Member object's toString method to get a string that describes
the member, skipping members that are inherited from Object (using
getDeclaringClass to see which class the member belongs to) since
these are present in all classes and so are not very useful to repeat each
time (
strip
removes any leading
"java.lang."
from the name). Here is
class Attr
public Attr(String)
public Attr(String, Object)
public String Attr.toString()
public String Attr.getName()
public Object Attr.getValue()
public Object Attr.setValue(Object)
Exercise 16.3
: Modify
ClassContents
to show information for all declared
and all public inherited members. Make sure you don't list anything
twice.
16.1.4. Naming Classes
The
Class
objects in the
TypeDesc
program are obtained using the static
method
Class.forName
, which takes a string argument and returns a
Class
object for the type with that name. The name must be the
binary name
of a class or interface, or else be a specially named array typethese are
defined below.