You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FinalFields.java 669B

123456789101112131415161718
  1. import java.io.Serializable;
  2. import java.lang.reflect.*;
  3. public class FinalFields implements Serializable {
  4. public static final Integer SUCCESS = new Integer(0);
  5. public static void main(String[] args) throws Exception {
  6. Class c = FinalFields.class;
  7. Field f = c.getDeclaredField("SUCCESS");
  8. int mods = f.getModifiers();
  9. System.out.println("modifers are: " + Modifier.toString(mods));
  10. if (!Modifier.isFinal(mods)) throw new RuntimeException("modifier should be final");
  11. if (!Modifier.isPublic(mods)) throw new RuntimeException("modifier should be public");
  12. if (!Modifier.isStatic(mods)) throw new RuntimeException("modifier should be static");
  13. }
  14. }