@@ -65,6 +65,9 @@ public abstract class ClassUtils {
65
65
/** Prefix for internal non-primitive array class names: {@code "[L"}. */
66
66
private static final String NON_PRIMITIVE_ARRAY_PREFIX = "[L" ;
67
67
68
+ /** A reusable empty class array constant. */
69
+ private static final Class <?>[] EMPTY_CLASS_ARRAY = {};
70
+
68
71
/** The package separator character: {@code '.'}. */
69
72
private static final char PACKAGE_SEPARATOR = '.' ;
70
73
@@ -543,17 +546,12 @@ public static boolean isAssignable(Class<?> lhsType, Class<?> rhsType) {
543
546
}
544
547
if (lhsType .isPrimitive ()) {
545
548
Class <?> resolvedPrimitive = primitiveWrapperTypeMap .get (rhsType );
546
- if (lhsType == resolvedPrimitive ) {
547
- return true ;
548
- }
549
+ return (lhsType == resolvedPrimitive );
549
550
}
550
551
else {
551
552
Class <?> resolvedWrapper = primitiveTypeToWrapperMap .get (rhsType );
552
- if (resolvedWrapper != null && lhsType .isAssignableFrom (resolvedWrapper )) {
553
- return true ;
554
- }
553
+ return (resolvedWrapper != null && lhsType .isAssignableFrom (resolvedWrapper ));
555
554
}
556
- return false ;
557
555
}
558
556
559
557
/**
@@ -681,8 +679,8 @@ public static String classNamesToString(@Nullable Collection<Class<?>> classes)
681
679
* @since 3.1
682
680
* @see StringUtils#toStringArray
683
681
*/
684
- public static Class <?>[] toClassArray (Collection <Class <?>> collection ) {
685
- return collection .toArray (new Class <?>[ 0 ] );
682
+ public static Class <?>[] toClassArray (@ Nullable Collection <Class <?>> collection ) {
683
+ return (! CollectionUtils . isEmpty ( collection ) ? collection .toArray (EMPTY_CLASS_ARRAY ) : EMPTY_CLASS_ARRAY );
686
684
}
687
685
688
686
/**
@@ -1062,7 +1060,7 @@ public static String getQualifiedMethodName(Method method, @Nullable Class<?> cl
1062
1060
* @param clazz the clazz to analyze
1063
1061
* @param paramTypes the parameter types of the method
1064
1062
* @return whether the class has a corresponding constructor
1065
- * @see Class#getMethod
1063
+ * @see Class#getConstructor
1066
1064
*/
1067
1065
public static boolean hasConstructor (Class <?> clazz , Class <?>... paramTypes ) {
1068
1066
return (getConstructorIfAvailable (clazz , paramTypes ) != null );
0 commit comments