Last change
on this file was 2, checked in by bird, 22 years ago |
Initial revision
|
-
Property cvs2svn:cvs-rev
set to
1.1
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
|
File size:
1.1 KB
|
Line | |
---|
1 | // Show a value given class name and constant name.
|
---|
2 |
|
---|
3 | /* Copyright (C) 2000 Free Software Foundation
|
---|
4 |
|
---|
5 | This file is part of libgcj.
|
---|
6 |
|
---|
7 | This software is copyrighted work licensed under the terms of the
|
---|
8 | Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
---|
9 | details. */
|
---|
10 |
|
---|
11 | /* Written by Tom Tromey <tromey@redhat.com>. */
|
---|
12 |
|
---|
13 | // Use like this to print a `static final' value (integers only, not
|
---|
14 | // strings yet):
|
---|
15 | // java showval java.awt.geom.AffineTransform.TYPE_IDENTITY
|
---|
16 | // Prints result like:
|
---|
17 | // TYPE_IDENTITY = 0
|
---|
18 | // In conjunction with a keyboard macro you can do a number of
|
---|
19 | // constants very easily.
|
---|
20 |
|
---|
21 | import java.lang.reflect.*;
|
---|
22 |
|
---|
23 | public class showval
|
---|
24 | {
|
---|
25 | public static void main (String[] args)
|
---|
26 | {
|
---|
27 | int ch = args[0].lastIndexOf ('.');
|
---|
28 | String className = args[0].substring (0, ch);
|
---|
29 | String constName = args[0].substring (ch + 1);
|
---|
30 | try
|
---|
31 | {
|
---|
32 | Class klass = Class.forName (className);
|
---|
33 | Field field = klass.getField (constName);
|
---|
34 | System.out.println (constName + " = " + field.getInt (null));
|
---|
35 | }
|
---|
36 | catch (Throwable _)
|
---|
37 | {
|
---|
38 | System.out.println (_);
|
---|
39 | }
|
---|
40 | }
|
---|
41 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.