本文整理了Java中java.lang.Class.isAnonymousClass()
方法的一些代码示例,展示了Class.isAnonymousClass()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.isAnonymousClass()
方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:isAnonymousClass
[英]Tests whether the class represented by this Class is anonymous.
[中]测试此类表示的类是否为匿名类。
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
public boolean isAnonymousType() {
return type.isAnonymousClass();
}
代码示例来源:origin: spring-projects/spring-loaded
public static boolean callIsAnonymousClass(Class thiz)
{
return thiz.isAnonymousClass();
}
代码示例来源:origin: redisson/redisson
public static Class getRealEnumClass(Class enumClass) {
if (enumClass.isAnonymousClass()) {
return enumClass.getSuperclass();
}
return enumClass;
}
}
代码示例来源:origin: redisson/redisson
protected void check(Object task) {
if (task == null) {
throw new NullPointerException("Task is not defined");
}
if (task.getClass().isAnonymousClass()) {
throw new IllegalArgumentException("Task can't be created using anonymous class");
}
if (task.getClass().isMemberClass()
&& !Modifier.isStatic(task.getClass().getModifiers())) {
throw new IllegalArgumentException("Task class is an inner class and it should be static");
}
}
代码示例来源:origin: redisson/redisson
private void check(Object task) {
if (task == null) {
throw new NullPointerException("Task is not defined");
}
if (task.getClass().isAnonymousClass()) {
throw new IllegalArgumentException("Task can't be created using anonymous class");
}
if (task.getClass().isMemberClass()
&& !Modifier.isStatic(task.getClass().getModifiers())) {
throw new IllegalArgumentException("Task class is an inner class and it should be static");
}
}
代码示例来源:origin: redisson/redisson
private void check(Object task) {
if (task == null) {
throw new NullPointerException("Task is not defined");
}
if (task.getClass().isAnonymousClass()) {
throw new IllegalArgumentException("Task can't be created using anonymous class");
}
if (task.getClass().isMemberClass()
&& !Modifier.isStatic(task.getClass().getModifiers())) {
throw new IllegalArgumentException("Task class is an inner class and it should be static");
}
}
代码示例来源:origin: redisson/redisson
protected void check(Object task) {
if (task == null) {
throw new NullPointerException("Task is not defined");
}
if (task.getClass().isAnonymousClass()) {
throw new IllegalArgumentException("Task can't be created using anonymous class");
}
if (task.getClass().isMemberClass()
&& !Modifier.isStatic(task.getClass().getModifiers())) {
throw new IllegalArgumentException("Task class is an inner class and it should be static");
}
}
代码示例来源:origin: apache/flink
private static boolean isAnonymousClass(Class clazz) {
final String name = clazz.getName();
// isAnonymousClass does not work for anonymous Scala classes; additionally check by class name
if (name.contains("$anon$") || name.contains("$anonfun") || name.contains("$macro$")) {
return true;
}
// calling isAnonymousClass or getSimpleName can throw InternalError for certain Scala types, see https://issues.scala-lang.org/browse/SI-2034
// until we move to JDK 9, this try-catch is necessary
try {
return clazz.isAnonymousClass();
} catch (InternalError e) {
return false;
}
}
代码示例来源:origin: eclipse-vertx/vert.x
/**
* @deprecated see https://github.com/eclipse-vertx/vert.x/issues/2774
*/
@Deprecated
public static Logger getLogger(final Class<?> clazz) {
String name = clazz.isAnonymousClass() ?
clazz.getEnclosingClass().getCanonicalName() :
clazz.getCanonicalName();
return getLogger(name);
}
代码示例来源:origin: prestodb/presto
public void register(PlanOptimizer optimizer)
{
requireNonNull(optimizer, "optimizer is null");
checkArgument(!optimizer.getClass().isAnonymousClass());
stats.put(optimizer.getClass(), new OptimizerStats());
}
代码示例来源:origin: prestodb/presto
public void registerAll(Collection<Rule<?>> rules)
{
for (Rule<?> rule : rules) {
checkArgument(!rule.getClass().isAnonymousClass());
stats.put(rule.getClass(), new RuleStats());
}
}
代码示例来源:origin: org.assertj/assertj-core
@Override
public String unambiguousToStringOf(Object obj) {
return obj == null ? null
: String.format("%s (%s@%s)",
toStringOf(obj),
obj.getClass().isAnonymousClass() ? obj.getClass().getName() : obj.getClass().getSimpleName(),
toHexString(System.identityHashCode(obj)));
}
代码示例来源:origin: nutzam/nutz
public boolean checkClass(Class<?> klass) {
return !(klass.isInterface()
|| klass.isArray()
|| klass.isEnum()
|| klass.isPrimitive()
|| klass.isMemberClass()
|| klass.isAnnotation()
|| klass.isAnonymousClass());
}
代码示例来源:origin: redisson/redisson
/**
* get cross platform symbolic class identifier
* @param cl
* @return
*/
public String getCPNameForClass( Class cl ) {
String res = minbinNamesReverse.get(cl.getName());
if (res == null) {
if (cl.isAnonymousClass()) {
return getCPNameForClass(cl.getSuperclass());
}
return cl.getName();
}
return res;
}
代码示例来源:origin: JakeWharton/hugo
private static String asTag(Class<?> cls) {
if (cls.isAnonymousClass()) {
return asTag(cls.getEnclosingClass());
}
return cls.getSimpleName();
}
}
代码示例来源:origin: apache/flink
private static String generateFunctionName(Function function) {
Class<? extends Function> functionClass = function.getClass();
if (functionClass.isAnonymousClass()) {
// getSimpleName returns an empty String for anonymous classes
Type[] interfaces = functionClass.getInterfaces();
if (interfaces.length == 0) {
// extends an existing class (like RichMapFunction)
Class<?> functionSuperClass = functionClass.getSuperclass();
return functionSuperClass.getSimpleName() + functionClass.getName().substring(functionClass.getEnclosingClass().getName().length());
} else {
// implements a Function interface
Class<?> functionInterface = functionClass.getInterfaces()[0];
return functionInterface.getSimpleName() + functionClass.getName().substring(functionClass.getEnclosingClass().getName().length());
}
} else {
return functionClass.getSimpleName();
}
}
代码示例来源:origin: square/javapoet
public static ClassName get(Class<?> clazz) {
checkNotNull(clazz, "clazz == null");
checkArgument(!clazz.isPrimitive(), "primitive types cannot be represented as a ClassName");
checkArgument(!void.class.equals(clazz), "'void' type cannot be represented as a ClassName");
checkArgument(!clazz.isArray(), "array types cannot be represented as a ClassName");
String anonymousSuffix = "";
while (clazz.isAnonymousClass()) {
int lastDollar = clazz.getName().lastIndexOf('$');
anonymousSuffix = clazz.getName().substring(lastDollar) + anonymousSuffix;
clazz = clazz.getEnclosingClass();
}
String name = clazz.getSimpleName() + anonymousSuffix;
if (clazz.getEnclosingClass() == null) {
// Avoid unreliable Class.getPackage(). https://github.com/square/javapoet/issues/295
int lastDot = clazz.getName().lastIndexOf('.');
String packageName = (lastDot != -1) ? clazz.getName().substring(0, lastDot) : null;
return new ClassName(packageName, null, name);
}
return ClassName.get(clazz.getEnclosingClass()).nestedClass(name);
}
代码示例来源:origin: querydsl/querydsl
@Override
public boolean apply(Class<?> input) {
return !input.isAnonymousClass()
&& !input.isMemberClass();
}
};
代码示例来源:origin: apache/kylin
private String getAggregatorName(Class<? extends MeasureAggregator> clazz) {
if (!clazz.isAnonymousClass()) {
return clazz.getSimpleName();
}
String[] parts = clazz.getName().split("\\.");
return parts[parts.length - 1];
}
代码示例来源:origin: apache/flink
private static void validataSerialVersionUID(Class<?> clazz) {
// all non-interface types must have a serial version UID
if (!clazz.isInterface()) {
assertFalse("Anonymous state handle classes have problematic serialization behavior: " + clazz,
clazz.isAnonymousClass());
try {
Field versionUidField = clazz.getDeclaredField("serialVersionUID");
// check conditions first via "if" to prevent always constructing expensive error messages
if (!(Modifier.isPrivate(versionUidField.getModifiers()) &&
Modifier.isStatic(versionUidField.getModifiers()) &&
Modifier.isFinal(versionUidField.getModifiers()))) {
fail(clazz.getName() + " - serialVersionUID is not 'private static final'");
}
}
catch (NoSuchFieldException e) {
fail("State handle implementation '" + clazz.getName() + "' is missing the serialVersionUID");
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!