Constructor and Description |
---|
ClassUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
getClassLoaderInfo(Class c)
Returns classloader information about the specified class.
|
static String |
getClassLoaderInfo(Object obj)
Returns classloader information about the specified object
|
static String |
getClassName()
This method can be called from either a instance or a static method.
|
static String |
getLoadedFromPath(Class caller)
Returns either the directory or jar file from which the specified class was loaded
|
static String |
getMainClassName()
Returns the fully qualified name of the class that contained the main() method used to
invoke the application.
|
static String |
getParentDir(Class caller)
Returns the right most parent directory from which the actual class was loaded.
|
static URL |
getParentDirAsURL(Class caller)
Returns the parent directory from which the actual class was loaded.
|
static boolean |
isSystemClass(Class c)
Returns true is the specified class is a system/JDK class.
|
static void |
main(String[] args) |
public ClassUtil()
public static String getClassLoaderInfo(Object obj)
public static String getClassLoaderInfo(Class c)
public static String getClassName()
Important note: The returned class name is wherever the method is invoked from. For instance methods, it is the runtime virtual class. For static it is the class name where the method was declared (static methods are not virtual and bound at compile time). For example:
Class A { static void foo(...) { System.out.print(ClassUtil.getClassName()); } } public class B extends A { } % java B will print: A (NOT B)
public static String getMainClassName()
public static boolean isSystemClass(Class c)
caller
- the object or Class
Class corresponding to that objectpublic static String getLoadedFromPath(Class caller)
This does not work for system/bootstrap classes and will return null for system classes.
caller
- the Class
class to be looked uppublic static String getParentDir(Class caller)
For classes loaded from other sources (jar, etc), the return value will be null.
This also does not work for system/bootstrap classes (they are typically loaded from jars) either (those will return null also)
caller
- the Class
class to be looked uppublic static URL getParentDirAsURL(Class caller)
For classes loaded from other sources (jar, etc), a URL will be returned. For jar URL's, the URL.getProtocol() method returns "jar", so that can be useful for further processing as needed.
caller
- the Class
class to be looked up