Skeleton Code
Use of the reflection API is important when creating tools. They need
to be able to inspect Java Beans to see how they work. This exercise
shows you how to duplicate javap functionality through the
use of the Reflection/Introspection capabilities of Java.
Perform the following tasks:
Import the reflection library.
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.
Within listClassMethods : for each method of the class, list
the modifiers, return type, name, and parameter types.
As time permits, you can do other things with this. To name just a few:
-
Sort each list.
-
Group private, protected, and public items together.
-
For classes in
java.lang , chop that part of their name off.
-
Catch security exceptions so this will run unsigned in an applet,
without generating lots of stack traces.
-
List only those methods that accept a user provided parameter list.
The task numbers above are linked to the
step-by-step help page. Also available
is a complete solution to the
problem, and expected behavior,
to demonstrate it.
Copyright © 1997 MageLang Institute. All Rights Reserved.
|
|