diff --git a/spring-core/src/main/java/org/springframework/util/ClassUtils.java b/spring-core/src/main/java/org/springframework/util/ClassUtils.java index c77dcba127..91a74aa3f8 100644 --- a/spring-core/src/main/java/org/springframework/util/ClassUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ClassUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -533,7 +533,7 @@ public abstract class ClassUtils { * @param lhsType the target type * @param rhsType the value type that should be assigned to the target type * @return if the target type is assignable from the value type - * @see TypeUtils#isAssignable + * @see TypeUtils#isAssignable(java.lang.reflect.Type, java.lang.reflect.Type) */ public static boolean isAssignable(Class lhsType, Class rhsType) { Assert.notNull(lhsType, "Left-hand side type must not be null"); @@ -1090,23 +1090,10 @@ public abstract class ClassUtils { /** * Determine whether the given class has a public method with the given signature. - *

Essentially translates {@code NoSuchMethodException} to "false". * @param clazz the clazz to analyze - * @param methodName the name of the method - * @param paramTypes the parameter types of the method + * @param method the method to look for * @return whether the class has a corresponding method - * @see Class#getMethod - */ - public static boolean hasMethod(Class clazz, String methodName, Class... paramTypes) { - return (getMethodIfAvailable(clazz, methodName, paramTypes) != null); - } - - /** - * Determine whether the given class has a public method with the given signature. - * @param clazz the clazz to analyze - * @param method checked method - * @return whether the class has a corresponding method - * @see Method#getDeclaringClass + * @since 5.2.3 */ public static boolean hasMethod(Class clazz, Method method) { Assert.notNull(clazz, "Class must not be null"); @@ -1119,6 +1106,19 @@ public abstract class ClassUtils { return getMethodOrNull(clazz, methodName, paramTypes) != null; } + /** + * Determine whether the given class has a public method with the given signature. + *

Essentially translates {@code NoSuchMethodException} to "false". + * @param clazz the clazz to analyze + * @param methodName the name of the method + * @param paramTypes the parameter types of the method + * @return whether the class has a corresponding method + * @see Class#getMethod + */ + public static boolean hasMethod(Class clazz, String methodName, Class... paramTypes) { + return (getMethodIfAvailable(clazz, methodName, paramTypes) != null); + } + /** * Determine whether the given class has a public method with the given signature, * and return it if available (else throws an {@code IllegalStateException}). @@ -1373,6 +1373,17 @@ public abstract class ClassUtils { } } + + @Nullable + private static Method getMethodOrNull(Class clazz, String methodName, Class[] paramTypes) { + try { + return clazz.getMethod(methodName, paramTypes); + } + catch (NoSuchMethodException ex) { + return null; + } + } + private static Set findMethodCandidatesByName(Class clazz, String methodName) { Set candidates = new HashSet<>(1); Method[] methods = clazz.getMethods(); @@ -1384,12 +1395,4 @@ public abstract class ClassUtils { return candidates; } - @Nullable - private static Method getMethodOrNull(Class clazz, String methodName, Class[] paramTypes) { - try { - return clazz.getMethod(methodName, paramTypes); - } catch (NoSuchMethodException ex) { - return null; - } - } }