Handy program

Tom Tromey tromey@cygnus.com
Sat Jul 15 19:10:00 GMT 2000


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 (_);
 }
 }
}


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /