This is the mail archive of the
java-discuss@sources.redhat.com
mailing list for the Java project.
Handy program
- To: Java Discuss List <java-discuss at sourceware dot cygnus dot com>
- Subject: Handy program
- From: Tom Tromey <tromey at cygnus dot com>
- Date: 15 Jul 2000 20:16:22 -0600
- Reply-To: tromey at cygnus dot com
I use the appended program to reverse-engineer `static final' fields.
(Then I use a keyboard macro to let me do a bunch of fields in a class
at once.)
Use it like "java showval java.awt.geom.AffineTransform.TYPE_IDENTITY".
I thought someone else might find this useful.
I wonder if we should have a directory for handy hacks like this.
Maybe it should go into Classpath instead.
Tom
// Show a value given class name and constant name.
import java.lang.reflect.*;
public class showval
{
public static void main (String[] args)
{
int ch = args[0].lastIndexOf ('.');
String className = args[0].substring (0, ch);
String constName = args[0].substring (ch + 1);
try
{
Class klass = Class.forName (className);
Field field = klass.getField (constName);
System.out.println (constName + " = " + field.getInt (null));
}
catch (Throwable _)
{
System.out.println (_);
}
}
}