public class ClassUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static boolean |
fileCanContainClasses(java.io.File file)
Determine whether a file is a jar file, zip file or directory (i.e.,
represents places that can be searched for classes).
|
static java.lang.String |
getShortClassName(java.lang.Class cls)
Strip the package name from a fully-qualified class name and return
just the short class name.
|
static java.lang.String |
getShortClassName(java.lang.String fullClassName)
Strip the package name from a fully-qualified class name and return
just the short class name.
|
static java.lang.Object |
instantiateClass(java.lang.String className)
Convenience method that loads a class and attempts to instantiate it
via its default constructor.
|
public static boolean fileCanContainClasses(java.io.File file)
file
- the file to checkpublic static java.lang.String getShortClassName(java.lang.String fullClassName)
fullClassName
- the full class namepublic static java.lang.String getShortClassName(java.lang.Class cls)
cls
- the Class object whose name is to be trimmedpublic static java.lang.Object instantiateClass(java.lang.String className) throws ClassUtilException
ClassUtilException
, reducing the number of lines of code
necessary to instantiate a class given its name. Note that this method
only catches and wraps checked exceptions. Unchecked exceptions,
such as ExceptionInInitializerError, are propagated directly
to the caller.className
- the fully-qualified class nameClassUtilException
- on error