showval.java 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Show a value given class name and constant name.
  2. /* Copyright (C) 2000 Free Software Foundation
  3. This file is part of libgcj.
  4. This software is copyrighted work licensed under the terms of the
  5. Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  6. details. */
  7. /* Written by Tom Tromey <tromey@redhat.com>. */
  8. // Use like this to print a `static final' value (integers only, not
  9. // strings yet):
  10. // java showval java.awt.geom.AffineTransform.TYPE_IDENTITY
  11. // Prints result like:
  12. // TYPE_IDENTITY = 0
  13. // In conjunction with a keyboard macro you can do a number of
  14. // constants very easily.
  15. import java.lang.reflect.*;
  16. public class showval
  17. {
  18. public static void main (String[] args)
  19. {
  20. int ch = args[0].lastIndexOf ('.');
  21. String className = args[0].substring (0, ch);
  22. String constName = args[0].substring (ch + 1);
  23. try
  24. {
  25. Class klass = Class.forName (className);
  26. Field field = klass.getField (constName);
  27. System.out.println (constName + " = " + field.getInt (null));
  28. }
  29. catch (Throwable _)
  30. {
  31. System.out.println (_);
  32. }
  33. }
  34. }