Package cn.sliew.milky.common.util
Class ClassUtil
- java.lang.Object
-
- cn.sliew.milky.common.util.ClassUtil
-
public final class ClassUtil extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ClassLoadergetClassLoader()Return the default ClassLoader to use: typically the thread context ClassLoader, if available; the ClassLoader that loaded the ClassUtils class will be used as fallback.static ClassLoadergetClassLoader(Class<?> clazz)get class loaderstatic StringnullSafeToString(Class<?> clazz)Get the fully qualified name of the supplied class.static StringnullSafeToString(Class<?>... classes)Generate a comma-separated list of fully qualified class names for the supplied classes.static StringnullSafeToString(Function<? super Class<?>,? extends String> mapper, Class<?>... classes)Generate a comma-separated list of mapped values for the supplied classes.
-
-
-
Method Detail
-
nullSafeToString
public static String nullSafeToString(Class<?> clazz)
Get the fully qualified name of the supplied class.This is a null-safe variant of
Class.getName().- Parameters:
clazz- the class whose name should be retrieved, potentiallynull- Returns:
- the fully qualified class name or
"null"if the supplied class reference isnull - See Also:
nullSafeToString(Class...),StringUtils.nullSafeToString(Object)
-
nullSafeToString
public static String nullSafeToString(Class<?>... classes)
Generate a comma-separated list of fully qualified class names for the supplied classes.- Parameters:
classes- the classes whose names should be included in the generated string- Returns:
- a comma-separated list of fully qualified class names, or an empty
string if the supplied class array is
nullor empty - See Also:
nullSafeToString(Function, Class...),StringUtils.nullSafeToString(Object)
-
nullSafeToString
public static String nullSafeToString(Function<? super Class<?>,? extends String> mapper, Class<?>... classes)
Generate a comma-separated list of mapped values for the supplied classes.The values are generated by the supplied
mapper(e.g.,Class::getName,Class::getSimpleName, etc.), unless a class reference isnullin which case it will be mapped to"null".- Parameters:
mapper- the mapper to use; nevernullclasses- the classes to map- Returns:
- a comma-separated list of mapped values, or an empty string if
the supplied class array is
nullor empty - See Also:
nullSafeToString(Class...),StringUtils.nullSafeToString(Object)
-
getClassLoader
public static ClassLoader getClassLoader()
Return the default ClassLoader to use: typically the thread context ClassLoader, if available; the ClassLoader that loaded the ClassUtils class will be used as fallback.Call this method if you intend to use the thread context ClassLoader in a scenario where you absolutely need a non-null ClassLoader reference: for example, for class path resource loading (but not necessarily for
Class.forName, which accepts anullClassLoader reference as well).- Returns:
- the default ClassLoader (never
null) - See Also:
Thread.getContextClassLoader()
-
getClassLoader
public static ClassLoader getClassLoader(Class<?> clazz)
get class loader- Parameters:
clazz-- Returns:
- class loader
-
-