publicclass Main { publicfinalstaticint INTERFACE_DEFINED_BITS = 0x0001 | // public, may be set. 0x0002 | // private, may be flagged by inner class. 0x0004 | // protected, may be flagged by inner class. 0x0008 | // static, may be flagged by inner class. 0x0010 | // final, must not be set. 0x0020 | // super, must not be set. 0x0200 | // interface, must be set. 0x0400 | // abstract, must be set. 0x1000 | // synthetic, may be set. 0x2000 | // annotation, may be set (annotation implies interface) 0x4000 ; // enum, must not be set.
publicfinalstaticint CLASS_DEFINED_BITS = 0x0001 | // public, may be set. 0x0002 | // private, may be flagged by inner class. 0x0004 | // protected, may be flagged by inner class. 0x0008 | // static, may be flagged by inner class. 0x0010 | // final, may be set. 0x0020 | // super, may be set. 0x0200 | // interface, must not be set. 0x0400 | // abstract, may be set. 0x1000 | // synthetic, may be set. 0x2000 | // annotation, must not be set. 0x4000 ; // enum, may be set.
privatestaticvoid check(String className) throws Exception { Class<?> clazz = Class.forName(className); if (className.equals("Inf")) { if (!clazz.isInterface()) { thrownew RuntimeException("Expected an interface.");
} int undefinedBits = 0xFFFF ^ INTERFACE_DEFINED_BITS; if ((clazz.getModifiers() & undefinedBits) != 0) {
System.out.println("Clazz.getModifiers(): " + Integer.toBinaryString(clazz.getModifiers()));
System.out.println("INTERFACE_DEF_BITS: " + Integer.toBinaryString(INTERFACE_DEFINED_BITS)); thrownew RuntimeException("Undefined bits for an interface: " + className);
}
} else { if (clazz.isInterface()) { thrownew RuntimeException("Expected a class.");
} int undefinedBits = 0xFFFF ^ CLASS_DEFINED_BITS; if ((clazz.getModifiers() & undefinedBits) != 0) {
System.out.println("Clazz.getModifiers(): " + Integer.toBinaryString(clazz.getModifiers()));
System.out.println("CLASS_DEF_BITS: " + Integer.toBinaryString(CLASS_DEFINED_BITS)); thrownew RuntimeException("Undefined bits for a class: " + className);
}
}
// Check fields. for (java.lang.reflect.Field f : clazz.getDeclaredFields()) {
String name = f.getName(); int undefinedBits = 0xFFFF ^ FIELD_DEFINED_BITS; if ((f.getModifiers() & undefinedBits) != 0) {
System.out.println("f.getModifiers(): " + Integer.toBinaryString(f.getModifiers()));
System.out.println("FIELD_DEF_BITS: " + Integer.toBinaryString(FIELD_DEFINED_BITS)); thrownew RuntimeException("Unexpected field bits: " + name);
} if (name.equals("I")) { // Interface field, just check generically.
} else { // Check the name, see that the corresponding bit is set. int bitmask = getFieldMask(name); if ((bitmask & f.getModifiers()) == 0) { thrownew RuntimeException("Expected field bit not set.");
}
}
}
// Check methods. for (java.lang.reflect.Method m : clazz.getDeclaredMethods()) {
String name = m.getName(); int undefinedBits = 0xFFFF ^ METHOD_DEFINED_BITS; if ((m.getModifiers() & undefinedBits) != 0) {
System.out.println("m.getModifiers(): " + Integer.toBinaryString(m.getModifiers()));
System.out.println("METHOD_DEF_BITS: " + Integer.toBinaryString(METHOD_DEFINED_BITS)); thrownew RuntimeException("Unexpected method bits: " + name);
} // Check the name, see that the corresponding bit is set. int bitmask = getMethodMask(name); if ((bitmask & m.getModifiers()) == 0) { thrownew RuntimeException("Expected method bit not set.");
}
}
}
privatestaticint getFieldMask(String name) { int index = name.indexOf("Field"); if (index > 0) {
String shortS = name.substring(0, index); if (shortS.equals("public")) { return0x0001;
} if (shortS.equals("private")) { return0x0002;
} if (shortS.equals("protected")) { return0x0004;
} if (shortS.equals("static")) { return0x0008;
} if (shortS.equals("transient")) { return0x0080;
} if (shortS.equals("volatile")) { return0x0040;
} if (shortS.equals("final")) { return0x0010;
}
} thrownew RuntimeException("Unexpected field name " + name);
}
privatestaticint getMethodMask(String name) { int index = name.indexOf("Method"); if (index > 0) {
String shortS = name.substring(0, index); if (shortS.equals("public")) { return0x0001;
} if (shortS.equals("private")) { return0x0002;
} if (shortS.equals("protected")) { return0x0004;
} if (shortS.equals("static")) { return0x0008;
} if (shortS.equals("synchronized")) { return0x0020;
} if (shortS.equals("varargs")) { return0x0080;
} if (shortS.equals("final")) { return0x0010;
} if (shortS.equals("native")) { return0x0100;
} if (shortS.equals("abstract")) { return0x0400;
} if (shortS.equals("strictfp")) { return0x0800;
}
} thrownew RuntimeException("Unexpected method name " + name);
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.