Status: dormant, better options likely exist; 2004-2005
Mirror is a Java program that uses Java's reflection to present an interactive view of classes and their parts. If your browser has Java, click the button below to launch it and start playing around. It will come up with a Welcome screen with some documentation. A slightly revised version of the documentation is below.
Mirror was written and (I believe) compiled for Java 1.4.2, but I've been using Java 1.5 tools recently; please tell me if I've made a mistake and it doesn't run on Java 1.4.2. Unfortunately, Mirror has not been updated for the new language features in Java 1.5, so its own interface does not show generics and so forth. What you can do is use Mirror to access the new Java 1.5 reflection classes.
Mirror is available for download in the form of a jar file containing the source code and the compiled code. It is really a Zip file with a different extension, so you can look inside with any Zip tool. But be cautioned that, since the files inside must be accessible to Java, I couldn't put everything in one nicely-named folder like people do these days; make yourself such a folder before extracting the file. You can launch Mirror from this file in any of the ways described in the Mirror documentation; the simplest is to type java -jar mirror-XXXX.XX.XX at the command line.
In version 2005.07.20, I made minor improvements. Mirror now has a button to recover objects you have named but to which you have lost all references, and it doesn't forget about all the presenters if you quit and relaunch it.
Description | File | Size | Modification time |
---|---|---|---|
Mirror version 2005.07.20 | mirror-2005.07.20.jar | 178961 | 2005-07-20 14:41:44 +0000 |
And here is the Mirror documentation.
Java's reflection mechanism allows Java programs to obtain information about the structure and capabilities of classes, constructors, methods, and fields at runtime. Programs can use program elements that they discover through reflection. For example, one could write a program that accepts a class name from the user, obtains a list of its methods through reflection, and invokes a random no-argument method.
Using Mirror, you can explore classes in the standard Java library or any others in your classpath. You can make new objects, run constructors and methods, and access fields. Mirror uses reflection to perform your requests.
By itself, Mirror is a new, compelling way to interact with and learn about Java. It can also be used to investigate objects created by other Java programs (primarily for debugging purposes, although there are many other tools better suited for this) or to test a Java library that has no user interface.
There are many different ways to launch Mirror. Which one you should use depends on what classes you want to investigate with Mirror.
You might start by opening a class using the box at the bottom of the control center. Type the name, including the package, in the box and click "Open class". Take a look at the information that Mirror provides about its constructors, methods, and fields on their respective tabs. If you've never used Java before, you might find these classes interesting:
Then, try constructing an object. To do so, open a constructor from the "Constructors" tab. Go to the "Invoke" tab, fill in any arguments, and hit "Invoke". A window will appear, presenting you with the constructed object. You can open it and call a method from the "Methods" tab; the procedure is similar.
A typical Mirror window (a ReflectorFrame in the source code) represents a class, constructor, method or field and may or may not carry a calling object of an appropriate type (look for the "Calling object" tab). When Mirror wants to show you an object, it simply opens a class window carrying that object, but it sets a flag so that the window title is the object name. (This is the object's identityHashCode unless you give it a custom name.) In all other cases, the window title is the name of the class, etc.
Whenever you use one Mirror window to open another, the new window gets the same calling object (if that object is of an appropriate type). To invoke a method on or access a field of a particular object, you must get a window representing that method or field and carrying the desired object; usually, this means opening the method or field from a class window carrying that object.
You also get a window (a CallFrame) for each constructor and method invocation. The window appears when you hit "Invoke" and will present you with a return value, a constructed object, or a Throwable when the call completes. Each call runs in its own thread so you can keep using Mirror while one is in progress.
You can hold references to objects you have created in the reflector bank on the control center. Actually, you can hold Reflectors, which are combinations of a program element (class, constructor, method, field) and optionally a calling object; each ReflectorFrame represents one. To deposit a reference, go to the object window and click "Grab". Then click "Add held" on the control center. The notion of "grabbing" serves as Mirror's object clipboard, and the box at the top of the control center shows what you are "holding".
The control center has a calculator that operates on primitive values with strict Java semantics. It is a postfix calculator, so you must push values onto the stack (by clicking the appropriate "Push" buttons) before you can operate on them.