privatestatic String modifierString(int v) { StringBuildersb=newStringBuilder(); if (Modifier.isPrivate(v)) sb.append("private "); if (Modifier.isPublic(v)) sb.append("public "); if (Modifier.isProtected(v)) sb.append("protected "); if (Modifier.isStatic(v)) sb.append("static "); if (Modifier.isAbstract(v)) sb.append("abstract "); if (Modifier.isFinal(v)) sb.append("final "); if (Modifier.isInterface(v)) sb.append("interface "); if (Modifier.isNative(v)) sb.append("native "); if (Modifier.isStrict(v)) sb.append("strict "); if (Modifier.isSynchronized(v)) sb.append("synchoronized "); if (Modifier.isTransient(v)) sb.append("transient "); if (Modifier.isVolatile(v)) sb.append("volatile "); return sb.toString(); } }
$ javac ReflectionTest.java && java ReflectionTest private int i = 123 protected long l = 9876543210 public float f = 1.23 public double d = 1.23456789 public static final java.lang.String s = foobar public int[] a = [I@70dea4e public int[][] a2 = [[I@5c647e05 public Foo obj = null public java.util.List list = null