|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Class
public final class Class
A Class represents a Java type. There will never be multiple Class objects with identical names and ClassLoaders. Primitive types, array types, and void also have a Class object.
Arrays with identical type and number of dimensions share the same class.
The array class ClassLoader is the same as the ClassLoader of the element
type of the array (which can be null to indicate the bootstrap classloader).
The name of an array class is [<signature format>;
.
For example,
String[]'s class is [Ljava.lang.String;
. boolean, byte,
short, char, int, long, float and double have the "type name" of
Z,B,S,C,I,J,F,D for the purposes of array classes. If it's a
multidimensioned array, the same principle applies:
int[][][]
== [[[I
.
There is no public constructor - Class objects are obtained only through the virtual machine, as defined in ClassLoaders.
ClassLoader
Method Summary | |
---|---|
static Class |
forName(String className)
Use the classloader of the current class to load, link, and initialize a class. |
String |
getName()
Get the name of this class, separated by dots for package separators. |
InputStream |
getResourceAsStream(String resourceName)
Get a resource using this class's package using the getClassLoader().getResourceAsStream() method. |
Object |
newInstance()
Get a new instance of this class by calling the no-argument constructor. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Class forName(String className) throws ClassNotFoundException
Class.forName(name, true, getClass().getClassLoader())
.
name
- the name of the class to find
ClassNotFoundException
- if the class was not found by the
classloader
LinkageError
- if linking the class fails
ExceptionInInitializerError
- if the class loads, but an exception
occurs during initializationpublic String getName()
Byte.TYPE.getName()
returns "byte".
Arrays are specially encoded as shown on this table.
array type [element type (note that the element type is encoded per this table) boolean Z byte B char C short S int I long J float F double D void V class or interface, alone: <dotted name> class or interface, as element type: L<dotted name>;
public InputStream getResourceAsStream(String resourceName)
If the name you supply is absolute (it starts with a /
),
then the leading /
is removed and it is passed on to
getResource(). If it is relative, the package name is prepended, and
.
's are replaced with /
.
The URL returned is system- and classloader-dependent, and could change across implementations.
resourceName
- the name of the resource, generally a path
NullPointerException
- if name is nullpublic Object newInstance() throws InstantiationException, IllegalAccessException
checkMemberAccess(this, Member.PUBLIC)
as well as checkPackageAccess
both having to succeed.
InstantiationException
- if there is not a no-arg constructor
for this class, including interfaces, abstract classes, arrays,
primitive types, and void; or if an exception occurred during
the constructor
IllegalAccessException
- if you are not allowed to access the
no-arg constructor because of scoping reasons
java.lang.SecurityException
- if the security check fails
ExceptionInInitializerError
- if class initialization caused by
this call fails with an exception
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |