Java Reference
In-Depth Information
Returns the
Constructor
object (discussed shortly) for the con-
structor in which this local or anonymous inner class was de-
clared. If this isn't a local or anonymous inner class declared
in a constructor, then
null
is returned.
public Method
getEnclosingMethod()
Returns the
Method
object (discussed shortly) for the method
in which this local or anonymous inner class was declared. If
this isn't a local or anonymous inner class declared in a meth-
od, then
null
is returned.
Exercise 16.1
: Modify
TypeDesc
to skip printing anything for the
Object
class. It is redundant because everything ultimately extends it. Use the
reference for the
Class
object for the
Object
type.
Exercise 16.2
: Modify
TypeDesc
to show whether the named type is a
nested type, and if so, what other type it is nested within.
16.1.3. Examining Class Members
The
Class
class contains a set of methods you can use to examine the
class's components: its fields, methods, constructors, and nested types.
Special types are defined to represent each of these, which you will learn
about in detail in later sections:
Field
objects for fields,
Method
objects
for methods,
Constructor
objects for constructors, and for nested types,
the
Class
objects you have already seen.
These methods come in four variants depending on whether you want
all members or a particular member, only public members or any mem-
bers, only members declared in the current class or inherited members
as well.
You can request all the public members of a specific kind that are either
declared in the class (interface) or inherited, by using one of the follow-
ing:
[2]