java.lang.reflect.Method.equals()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中java.lang.reflect.Method.equals()方法的一些代码示例,展示了Method.equals()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Method.equals()方法的具体详情如下:
包路径:java.lang.reflect.Method
类名称:Method
方法名:equals

Method.equals介绍

[英]Compares this Method against the specified object. Returns true if the objects are the same. Two Methods are the same if they were declared by the same class and have the same name and formal parameter types and return type.
[中]将此方法与指定的对象进行比较。如果对象相同,则返回true。如果两个方法由同一个类声明,并且具有相同的名称、形式参数类型和返回类型,则它们是相同的。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public boolean equals(Object other) {
  if (this == other) {
    return true;
  }
  if (!(other instanceof AdviceExcludingMethodMatcher)) {
    return false;
  }
  AdviceExcludingMethodMatcher otherMm = (AdviceExcludingMethodMatcher) other;
  return this.adviceMethod.equals(otherMm.adviceMethod);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public boolean matches(Method method, Class<?> targetClass) {
  return !this.adviceMethod.equals(method);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public boolean equals(Object other) {
  if (this == other) {
    return true;
  }
  if (!(other instanceof HandlerMethod)) {
    return false;
  }
  HandlerMethod otherMethod = (HandlerMethod) other;
  return (this.bean.equals(otherMethod.bean) && this.method.equals(otherMethod.method));
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public boolean equals(Object other) {
  if (this == other) {
    return true;
  }
  if (!(other instanceof MethodClassKey)) {
    return false;
  }
  MethodClassKey otherKey = (MethodClassKey) other;
  return (this.method.equals(otherKey.method) &&
      ObjectUtils.nullSafeEquals(this.targetClass, otherKey.targetClass));
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public boolean equals(Object other) {
  if (this == other) {
    return true;
  }
  if (!(other instanceof HandlerMethod)) {
    return false;
  }
  HandlerMethod otherMethod = (HandlerMethod) other;
  return (this.bean.equals(otherMethod.bean) && this.method.equals(otherMethod.method));
}

代码示例来源:origin: org.mockito/mockito-core

/**
 * @return True if the input object is a DelegatingMethod which has an internal Method which is equal to the internal Method of this DelegatingMethod,
 * or if the input object is a Method which is equal to the internal Method of this DelegatingMethod.
 */
@Override
public boolean equals(Object o) {
  if (this == o) {
    return true;
  }
  if (o instanceof DelegatingMethod) {
    DelegatingMethod that = (DelegatingMethod) o;
    return method.equals(that.method);
  } else {
    return method.equals(o);
  }
}

代码示例来源:origin: spring-projects/spring-framework

private void addExceptionMapping(Class<? extends Throwable> exceptionType, Method method) {
  Method oldMethod = this.mappedMethods.put(exceptionType, method);
  if (oldMethod != null && !oldMethod.equals(method)) {
    throw new IllegalStateException("Ambiguous @ExceptionHandler method mapped for [" +
        exceptionType + "]: {" + oldMethod + ", " + method + "}");
  }
}

代码示例来源:origin: prestodb/presto

@Override
public boolean equals(Object obj) {
 if (obj == this) {
  return true;
 }
 if (!(obj instanceof AndroidTrustRootIndex)) {
  return false;
 }
 AndroidTrustRootIndex that = (AndroidTrustRootIndex) obj;
 return trustManager.equals(that.trustManager)
     && findByIssuerAndSignatureMethod.equals(that.findByIssuerAndSignatureMethod);
}

代码示例来源:origin: junit-team/junit4

@Override
public boolean equals(Object obj) {
  if (!FrameworkMethod.class.isInstance(obj)) {
    return false;
  }
  return ((FrameworkMethod) obj).method.equals(method);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Returns {@code true} if the supplied '{@code candidateMethod}' can be
 * consider a validate candidate for the {@link Method} that is {@link Method#isBridge() bridged}
 * by the supplied {@link Method bridge Method}. This method performs inexpensive
 * checks and can be used quickly filter for a set of possible matches.
 */
private static boolean isBridgedCandidateFor(Method candidateMethod, Method bridgeMethod) {
  return (!candidateMethod.isBridge() && !candidateMethod.equals(bridgeMethod) &&
      candidateMethod.getName().equals(bridgeMethod.getName()) &&
      candidateMethod.getParameterCount() == bridgeMethod.getParameterCount());
}

代码示例来源:origin: google/guava

@Override
public final boolean equals(@Nullable Object obj) {
 if (obj instanceof Subscriber) {
  Subscriber that = (Subscriber) obj;
  // Use == so that different equal instances will still receive events.
  // We only guard against the case that the same object is registered
  // multiple times
  return target == that.target && method.equals(that.method);
 }
 return false;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Find a JavaBeans {@code PropertyDescriptor} for the given method,
 * with the method either being the read method or the write method for
 * that bean property.
 * @param method the method to find a corresponding PropertyDescriptor for
 * @param clazz the (most specific) class to introspect for descriptors
 * @return the corresponding PropertyDescriptor, or {@code null} if none
 * @throws BeansException if PropertyDescriptor lookup fails
 * @since 3.2.13
 */
@Nullable
public static PropertyDescriptor findPropertyForMethod(Method method, Class<?> clazz) throws BeansException {
  Assert.notNull(method, "Method must not be null");
  PropertyDescriptor[] pds = getPropertyDescriptors(clazz);
  for (PropertyDescriptor pd : pds) {
    if (method.equals(pd.getReadMethod()) || method.equals(pd.getWriteMethod())) {
      return pd;
    }
  }
  return null;
}

代码示例来源:origin: spring-projects/spring-framework

private List<AliasDescriptor> getOtherDescriptors() {
  List<AliasDescriptor> otherDescriptors = new ArrayList<>();
  for (Method currentAttribute : getAttributeMethods(this.sourceAnnotationType)) {
    if (!this.sourceAttribute.equals(currentAttribute)) {
      AliasDescriptor otherDescriptor = AliasDescriptor.from(currentAttribute);
      if (otherDescriptor != null) {
        otherDescriptors.add(otherDescriptor);
      }
    }
  }
  return otherDescriptors;
}

代码示例来源:origin: prestodb/presto

@Override
public final boolean equals(@NullableDecl Object obj) {
 if (obj instanceof Subscriber) {
  Subscriber that = (Subscriber) obj;
  // Use == so that different equal instances will still receive events.
  // We only guard against the case that the same object is registered
  // multiple times
  return target == that.target && method.equals(that.method);
 }
 return false;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Match the specified method by {@link Method} reference or method name.
 * <p>For backwards compatibility reasons, in a scenario with overloaded
 * non-abstract methods of the given name, only the no-arg variant of a
 * method will be turned into a container-driven lookup method.
 * <p>In case of a provided {@link Method}, only straight matches will
 * be considered, usually demarcated by the {@code @Lookup} annotation.
 */
@Override
public boolean matches(Method method) {
  if (this.method != null) {
    return method.equals(this.method);
  }
  else {
    return (method.getName().equals(getMethodName()) && (!isOverloaded() ||
        Modifier.isAbstract(method.getModifiers()) || method.getParameterCount() == 0));
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Checks if the method defined on the base type with the given arguments
 * is overridden in the given derived type.
 */
public static boolean isOverridden(@Nonnull Class base, @Nonnull Class derived, @Nonnull String methodName, @Nonnull Class... types) {
  return !getMethod(base, methodName, types).equals(getMethod(derived, methodName, types));
}

代码示例来源:origin: spring-projects/spring-framework

private static Map<Class<? extends Throwable>, Method> initExceptionMappings(Class<?> handlerType) {
  Map<Method, MessageExceptionHandler> methods = MethodIntrospector.selectMethods(handlerType,
      (MethodIntrospector.MetadataLookup<MessageExceptionHandler>) method ->
          AnnotatedElementUtils.findMergedAnnotation(method, MessageExceptionHandler.class));
  Map<Class<? extends Throwable>, Method> result = new HashMap<>();
  for (Map.Entry<Method, MessageExceptionHandler> entry : methods.entrySet()) {
    Method method = entry.getKey();
    List<Class<? extends Throwable>> exceptionTypes = new ArrayList<>();
    exceptionTypes.addAll(Arrays.asList(entry.getValue().value()));
    if (exceptionTypes.isEmpty()) {
      exceptionTypes.addAll(getExceptionsFromMethodSignature(method));
    }
    for (Class<? extends Throwable> exceptionType : exceptionTypes) {
      Method oldMethod = result.put(exceptionType, method);
      if (oldMethod != null && !oldMethod.equals(method)) {
        throw new IllegalStateException("Ambiguous @ExceptionHandler method mapped for [" +
            exceptionType + "]: {" + oldMethod + ", " + method + "}");
      }
    }
  }
  return result;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Determine if this descriptor and the supplied descriptor both
 * effectively represent aliases for the same attribute in the same
 * target annotation, either explicitly or implicitly.
 * <p>This method searches the attribute override hierarchy, beginning
 * with this descriptor, in order to detect implicit and transitively
 * implicit aliases.
 * @return {@code true} if this descriptor and the supplied descriptor
 * effectively alias the same annotation attribute
 * @see #isOverrideFor
 */
private boolean isAliasFor(AliasDescriptor otherDescriptor) {
  for (AliasDescriptor lhs = this; lhs != null; lhs = lhs.getAttributeOverrideDescriptor()) {
    for (AliasDescriptor rhs = otherDescriptor; rhs != null; rhs = rhs.getAttributeOverrideDescriptor()) {
      if (lhs.aliasedAttribute.equals(rhs.aliasedAttribute)) {
        return true;
      }
    }
  }
  return false;
}

代码示例来源:origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public boolean represents(Method method) {
  return this.method.equals(method) || equals(new MethodDescription.ForLoadedMethod(method));
}

代码示例来源:origin: google/guava

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
 return method.equals(getAllStatesMethod)
   ? getAllStates()
   : invokeListMethod(method, args);
}

相关文章

微信公众号

最新文章

更多