Class.isXXXメソッド
1894 ワード
private static class TestInner{
private String pv = " ";
}
public static void main(String[] args) throws Exception{
// 、 ,Map HashMap
System.out.println("isAssignableFrom():"+Map.class.isAssignableFrom(HashMap.class));
// boolean, byte, char, short, int, long, float, and double.
System.out.println("isPrimitive():"+int.class.isPrimitive());
//
class TestLocal{};
System.out.println("isLocalClass():"+TestLocal.class.isLocalClass());
//
System.out.println("isMemberClass():"+TestInner.class.isMemberClass());
/*AOP, generics, enums uses Java synthetic
http://javapapers.com/core-java/java-synthetic-class-method-field/*/
TestInner inner = new TestInner();
String pv = inner.pv;//
Class<?> c = inner.getClass();
Method[] methods = c.getDeclaredMethods();
for (Method m : methods) {
System.out.println("isSynthetic(): " + m.isSynthetic() + " //" + m);
}
//TODO: Class.isSynthetic=true
}
Classクラスフラグメントリファレンス:
private static final int SYNTHETIC = 0x00001000;//16 3 =4096
public native int getModifiers();
public boolean isSynthetic() {
return (getModifiers() & SYNTHETIC) != 0;
}
Modifierクラスフラグメントリファレンス:
public static final int PUBLIC 1
public static final int PROTECTED 4
public static final int PRIVATE 2
public static final int ABSTRACT 1024
public static final int STATIC 8
public static final int FINAL 16
public static final int STRICT 2048
private static final int CLASS_MODIFIERS =
Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL |
Modifier.STRICT;
public static int classModifiers() {
return CLASS_MODIFIERS;
}