Help is available for each task, or you can go straight to
the solution source code.
Task 1
Import the reflection library.
import java.lang.reflect.*;
Task 2
The skeleton code currently lists class variables and constructors of any class requested.
It is your job to have it also list all the methods. The framework is included, you only need
to complete the listClassMethods method.
The Class.getDeclaredMethods method lists all methods of a class.
The Class.getMethods method includes those methods inherited.
Task 3
Within listClassMethods: for each method of the class, list the modifiers,
return type, name, and parameter types.
-
The
Method.getModifiers
method lists a method's modifiers.
-
The
Method.getReturnType method reports a method's return type.
-
The
Method.getName method reports a method's name.
-
The
Method.getParameterTypes method lists a
method's parameter classes.
-
The
Method.getExceptionTypes method lists the exceptions a method throws.
However, this does not work with the 1.1 JDK.
The Method.toString method could be used, but we do
not want each method name prefixed by the name of the class it belongs to.
The private getTypeName method can be used to display the various
parameter types. If you do not use this method, you have to convert each
array parameter type yourself.
For those unfamiliar with
PrintWriter, this
is the 1.1 replacement class for PrintStream.
Copyright © 1997 MageLang Institute. All Rights Reserved.