本文整理汇总了Java中java.lang.reflect.Modifier.classModifiers方法的典型用法代码示例。如果您正苦于以下问题:Java Modifier.classModifiers方法的具体用法?Java Modifier.classModifiers怎么用?Java Modifier.classModifiers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Modifier
的用法示例。
在下文中一共展示了Modifier.classModifiers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getModifiersTest
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
@Test
public void getModifiersTest() {
for (Class<?> c : classes) {
ResolvedJavaType type = metaAccess.lookupJavaType(c);
int mask = Modifier.classModifiers() & ~Modifier.STATIC;
int expected = c.getModifiers() & mask;
int actual = type.getModifiers() & mask;
Class<?> elementalType = c;
while (elementalType.isArray()) {
elementalType = elementalType.getComponentType();
}
if (elementalType.isMemberClass()) {
// member class get their modifiers from the inner-class attribute in the JVM and
// from the classfile header in jvmci
expected &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
actual &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
}
assertEquals(String.format("%s: 0x%x != 0x%x", type, expected, actual), expected, actual);
}
}
示例2: toGenericString
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}