This is the mail archive of the java-discuss@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Handy program


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]