Introduce ClassUtils.isStaticClass() utility method

The impetus for this is to be able to use ClassUtils::isStaticClass
or the existing ClassUtils::isInnerClass as a method reference for
class-based predicates that need to differentiate between static
nested types and inner classes.

See gh-28207
This commit is contained in:
Sam Brannen 2022-03-22 16:18:14 +01:00
parent 52d5452381
commit 23d0240dc7
1 changed files with 13 additions and 1 deletions

View File

@ -831,15 +831,27 @@ public abstract class ClassUtils {
return javaLanguageInterfaces.contains(ifc);
}
/**
* Determine if the supplied class is a static class.
* @return {@code true} if the supplied class is a static class
* @since 6.0
* @see Modifier#isStatic(int)
* @see #isInnerClass(Class)
*/
public static boolean isStaticClass(Class<?> clazz) {
return Modifier.isStatic(clazz.getModifiers());
}
/**
* Determine if the supplied class is an <em>inner class</em>,
* i.e. a non-static member of an enclosing class.
* @return {@code true} if the supplied class is an inner class
* @since 5.0.5
* @see Class#isMemberClass()
* @see #isStaticClass(Class)
*/
public static boolean isInnerClass(Class<?> clazz) {
return (clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers()));
return (clazz.isMemberClass() && !isStaticClass(clazz));
}
/**