All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----harpoon.ClassFile.HClass
HClass
represent classes and
interfaces of a java program. Every array also belongs to a
class that is reflected as a HClass
object that is
shared by all arrays with the same element type and number of
dimensions. Finally, the primitive Java types
(boolean
, byte
, char
,
short
, int
, long
,
float
, and double
) and the keyword
void
are also represented as HClass
objects.
There is no public constructor for the class HClass
.
HClass
objects are created with the forName
,
forDescriptor
and forClass
methods of this
class.
HClass
object representing the primitive type boolean.
HClass
object representing the primitive type byte.
HClass
object representing the primitive type char.
HClass
object representing the primitive type double.
HClass
object representing the primitive type float.
HClass
object representing the primitive type int.
HClass
object representing the primitive type long.
HClass
object representing the primitive type short.
HClass
object representing the primitive type void.
HClass
object associated with the given java
Class
object.
HClass
object associated with the
ComponentType descriptor given.
HClass
object associated with the class with
the given string name.
null
.
HClass
object representing the component type of the array; otherwise returns
null.
HConstructor
object that reflects the
specified declared constructor of the class or interface represented
by this HClass
object.
HConstructor
objects reflecting
all the constructors declared by the class represented by the
HClass
object.
HField
object that reflects the specified
declared field of the class or interface represented by this
HClass
object.
HField
objects reflecting all the
fields declared by the class or interface represented by this
HClass
object.
HMethod
object that reflects the specified
declared method of the class or interface represented by this
HClass
object.
HMethod
object that reflects the specified
declared method of the class or interface represented by this
HClass
object.
HMethod
objects reflecting all the
methods declared by the class or interface represented by this
HClass
object.
HClass
object.
HField
object that reflects the specified
accessible member field of the class or interface represented by this
HClass
object.
HField
objects reflecting
all the accessible fields of the class or interface represented by this
HClass
object.
HMethod
object that reflects the specified
accessible method of the class or interface represented by this
HClass
object.
HMethod
object that reflects the specified
accessible method of the class or interface represented by this
HClass
object.
HMethod
object reflecting
all accessible member methods of the class or interface represented
by this HClass
object, including those declared by
the class or interface and those inherited from superclasses and
superinterfaces.
HClass
object,
as a String
.
HClass
.
Object
, then the object that represents the superclass of
that class is returned.
HClass
is a primitive type, return the
wrapper class for values of this type.
HClass
object represents an array type,
returns true
, otherwise returns false
.
HClass
object is either the same as, or is a superclass
or superinterface of, the class or interface represented by the
specified HClass
parameter.
instanceof
operator.
HClass
object represents an
interface type.
HClass
object represents a
primitive Java type.
HClass
is a superclass of a given
HClass hc
.
public static final HClass Boolean
HClass
object representing the primitive type boolean.
public static final HClass Byte
HClass
object representing the primitive type byte.
public static final HClass Short
HClass
object representing the primitive type short.
public static final HClass Int
HClass
object representing the primitive type int.
public static final HClass Long
HClass
object representing the primitive type long.
public static final HClass Float
HClass
object representing the primitive type float.
public static final HClass Double
HClass
object representing the primitive type double.
public static final HClass Char
HClass
object representing the primitive type char.
public static final HClass Void
HClass
object representing the primitive type void.
public HClass()
public static HClass forName(String className)
HClass
object associated with the class with
the given string name. Given the fully-qualified name for a class or
interface, this method attempts to locate and load the class. If it
succeeds, returns the HClass
object representing the class.
If it fails, the method throws a NoClassDefFoundError
.
HClass
descriptor for the class with the
specified name.
public static HClass forDescriptor(String descriptor)
HClass
object associated with the
ComponentType descriptor given. Throws NoClassDefFoundError
if the descriptor references a class that cannot be found. Throws
Error
if an invalid descriptor is given.
public static HClass forClass(Class cls)
HClass
object associated with the given java
Class
object. If (for some reason) the class file
cannot be found, the method throws a NoClassDefFoundError
.
HClass
descriptor for this Class
.
public HClass getComponentType()
HClass
object representing the component type of the array; otherwise returns
null.
public abstract String getName()
HClass
object,
as a String
.
public String getPackage()
HClass
. If this
HClass
represents a primitive or array type,
then returns null. Returns ""
(a zero-length string)
if this class is not in a package.
public abstract String getDescriptor()
HClass
object.
public HField getDeclaredField(String name) throws NoSuchFieldError
HField
object that reflects the specified
declared field of the class or interface represented by this
HClass
object. The name
parameter is a
String
that specifies the simple name of the
desired field.
public abstract HField[] getDeclaredFields()
HField
objects reflecting all the
fields declared by the class or interface represented by this
HClass
object. This includes public
,
protected
, default (package
) access,
and private
fields, but excludes inherited fields.
Returns an array of length 0 if the class or interface declares
no fields, or if this HClass
object represents a
primitive type.
public HField getField(String name) throws NoSuchFieldError
HField
object that reflects the specified
accessible member field of the class or interface represented by this
HClass
object. The name
parameter is
a String
specifying the simple name of the
desired field.
The field to be reflected is located by searching all member fields
of the class or interface represented by this HClass
object (and its superclasses and interfaces) for an accessible
field with the specified name.
public HField[] getFields()
HField
objects reflecting
all the accessible fields of the class or interface represented by this
HClass
object. Returns an array of length 0 if the
class or interface has no accessible fields, or if it represents an
array type or a primitive type.
Specifically, if this HClass
object represents a class,
returns the accessible fields of this class and of all its superclasses.
If this HClass
object represents an interface, returns
the accessible fields
of this interface and of all its superinterfaces. If this
HClass
object represents an array type or a primitive
type, returns an array of length 0.
The implicit length field for array types is not reflected by this method.
public HMethod getDeclaredMethod(String name, HClass parameterTypes[]) throws NoSuchMethodError
HMethod
object that reflects the specified
declared method of the class or interface represented by this
HClass
object. The name
parameter is a
String
that specifies the simple name of the desired
method, and the parameterTypes
parameter is an array
of HClass
objects that identify the method's formal
parameter types, in declared order.
public HMethod getDeclaredMethod(String name, String descriptor) throws NoSuchMethodError
HMethod
object that reflects the specified
declared method of the class or interface represented by this
HClass
object. The name
parameter is a
String
that specifies the simple name of the desired
method, and descriptor
is a string describing
the parameter types and return value of the method.
public abstract HMethod[] getDeclaredMethods()
HMethod
objects reflecting all the
methods declared by the class or interface represented by this
HClass
object. This includes public
,
protected
, default (package
) access, and
private
methods, but excludes inherited methods.
Returns an array of length 0 if the class or interface declares no
methods, or if this HClass
object represents a primitive
type.Constructors are included.
public HMethod getMethod(String name, HClass parameterTypes[]) throws NoSuchMethodError
HMethod
object that reflects the specified
accessible method of the class or interface represented by this
HClass
object. The name
parameter is
a string specifying the simple name of the desired method, and
the parameterTypes
parameter is an array of
HClass
objects that identify the method's formal
parameter types, in declared order.
The method to reflect is located by searching all the member methods
of the class or interface represented by this HClass
object for an accessible method with the specified name and exactly
the same formal parameter types.
public HMethod getMethod(String name, String descriptor) throws NoSuchMethodError
HMethod
object that reflects the specified
accessible method of the class or interface represented by this
HClass
object. The name
parameter is
a string specifying the simple name of the desired method, and
the descriptor
is a string describing the
parameter types and return value of the method.
The method is located by searching all the member methods of
the class or interface represented by this HClass
object for an accessible method with the specified name and
exactly the same descriptor.
public HMethod[] getMethods()
HMethod
object reflecting
all accessible member methods of the class or interface represented
by this HClass
object, including those declared by
the class or interface and those inherited from superclasses and
superinterfaces. Returns an array of length 0 if the class or
interface has no public member methods, or if the HClass
corresponds to a primitive type or array type.Constructors are included.
public HConstructor getConstructor(HClass parameterTypes[]) throws NoSuchMethodError
HConstructor
object that reflects the
specified declared constructor of the class or interface represented
by this HClass
object. The parameterTypes
parameter is an array of HClass
objects that
identify the constructor's formal parameter types, in declared order.
public HConstructor[] getConstructors()
HConstructor
objects reflecting
all the constructors declared by the class represented by the
HClass
object. These are public
,
protected
, default (package) access, and
private
constructors. Returns an array of length 0
if this HClass
object represents an interface or a
primitive type.
public HMethod getClassInitializer()
null
.
public abstract int getModifiers()
public abstract HClass getSuperclass()
Object
, then the object that represents the superclass of
that class is returned.
If this object is the one that represents the class
Object
or this object represents an interface,
null
is returned.
public abstract HClass[] getInterfaces()
If this object represents a class, the return value is an array containing objects representing all interfaces implemented by the class. The order of the interface objects in the array corresponds to the order of the interface names in the implements clause of the declaration of the class represented by this object.
If the object represents an interface, the array contains objects representing all interfaces extended by the interface. The order of the interface objects in the array corresponds to the order of the interface names in the extends clause of the declaration of the interface represented by this object.
If the class or interface implements no interfaces, the method returns an array of length 0.
public String getSourceFile()
public HClass getWrapper()
HClass
is a primitive type, return the
wrapper class for values of this type. For example:
HClass.forDescriptor("I").getWrapper()
will return HClass.forName("java.lang.Integer")
.
Calling getWrapper
with a non-primitive HClass
will return the value null
.
public boolean isArray()
HClass
object represents an array type,
returns true
, otherwise returns false
.
public boolean isInterface()
HClass
object represents an
interface type.
true
is this object represents an interface;
false
otherwise.
public boolean isPrimitive()
HClass
object represents a
primitive Java type.
There are nine predefined HClass
objects to represent
the eight primitive Java types and void.
public boolean isAssignableFrom(HClass cls)
HClass
object is either the same as, or is a superclass
or superinterface of, the class or interface represented by the
specified HClass
parameter. It returns
true
if so, false
otherwise. If this
HClass
object represents a primitive type, returns
true
if the specified HClass
parameter is
exactly this HClass
object, false
otherwise.
Specifically, this method tests whether the type represented
by the specified HClass
parameter can be converted
to the type represented by this HClass
object via an
identity conversion or via a widening reference conversion.
HClass
parameter is null.
public boolean isInstance(Object obj)
instanceof
operator. The method returns
true
if the specified Object
argument
is non-null and can be cast to the reference type represented by
this HClass
object without raising a
ClassCastException
. It returns false
otherwise.
Specifically, if this HClass
object represents a declared
class, return true
is the specified Object
argument is an instance of the represented class (or any of its
subclasses); false
otherwise. If this HClass
object represents an array class, returns true
if the
specified Object
argument can be converted to an object
of the array type by an identity conversion or by a widening reference
conversion, false
otherwise. If this HClass
object represents an interface, returns true
if the
class or any superclass of the specified Object
argument
implements this interface, false
otherwise. If this
HClass
object represents a primitive type, returns
false
.
public boolean isSuperclassOf(HClass hc)
HClass
is a superclass of a given
HClass hc
.
true
if this
is a superclass of
hc
, false
otherwise.
public int hashCode()
public abstract String toString()
"class"
or "interface"
followed by
a space and then the fully qualified name of the class. If this
HClass
object represents a primitive type,
returns the name of the primitive type.
public void print(PrintWriter pw)
All Packages Class Hierarchy This Package Previous Next Index