java.lang.Object | |
↳ | java.lang.ClassLoader |
Known Direct Subclasses |
Known Indirect Subclasses |
Loads classes and resources from a repository. One or more class loaders are installed at runtime. These are consulted whenever the runtime system needs a specific class that is not yet available in-memory. Typically, class loaders are grouped into a tree where child class loaders delegate all requests to parent class loaders. Only if the parent class loader cannot satisfy the request, the child class loader itself tries to handle it.
ClassLoader
is an abstract class that implements the common
infrastructure required by all class loaders. Android provides several
concrete implementations of the class, with
PathClassLoader
being the one typically used. Other
applications may implement subclasses of ClassLoader
to provide
special ways for loading classes.
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new instance of this class with the system class loader as
its parent.
| |||||||||||
Constructs a new instance of this class with the specified class loader
as its parent.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Sets the default assertion status for this class loader to
false
and removes any package default and class assertion status settings. | |||||||||||
Returns this class loader's parent.
| |||||||||||
Returns the URL of the resource with the specified name.
| |||||||||||
Returns a stream for the resource with the specified name.
| |||||||||||
Returns an enumeration of URLs for the resource with the specified name.
| |||||||||||
Returns the system class loader.
| |||||||||||
Finds the URL of the resource with the specified name.
| |||||||||||
Returns a stream for the resource with the specified name.
| |||||||||||
Returns an enumeration of URLs for the resource with the specified name.
| |||||||||||
Loads the class with the specified name.
| |||||||||||
Sets the assertion status of the class with the specified name.
| |||||||||||
Sets the default assertion status for this class loader.
| |||||||||||
Sets the assertion status of the package with the specified name.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This method is deprecated.
Use
defineClass(String, byte[], int, int) | |||||||||||
Defines a new class with the specified name, byte code from the byte
buffer and the optional protection domain.
| |||||||||||
Constructs a new class from an array of bytes containing a class
definition in class file format and assigns the specified protection
domain to the new class.
| |||||||||||
Constructs a new class from an array of bytes containing a class
definition in class file format.
| |||||||||||
Defines and returns a new
Package using the specified
information. | |||||||||||
Overridden by subclasses, throws a
ClassNotFoundException by
default. | |||||||||||
Returns the absolute path of the native library with the specified name,
or
null . | |||||||||||
Returns the class with the specified name if it has already been loaded
by the virtual machine or
null if it has not yet been loaded. | |||||||||||
Finds the URL of the resource with the specified name.
| |||||||||||
Finds an enumeration of URLs for the resource with the specified name.
| |||||||||||
Finds the class with the specified name, loading it using the system
class loader if necessary.
| |||||||||||
Returns the package with the specified name.
| |||||||||||
Returns all the packages known to this class loader.
| |||||||||||
Loads the class with the specified name, optionally linking it after
loading.
| |||||||||||
Forces a class to be linked (initialized).
| |||||||||||
Sets the signers of the specified class.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
Constructs a new instance of this class with the system class loader as its parent.
SecurityException | if a security manager exists and it does not allow the
creation of a new ClassLoader . |
---|
Constructs a new instance of this class with the specified class loader as its parent.
parentLoader | The ClassLoader to use as the new class loader's
parent. |
---|
SecurityException | if a security manager exists and it does not allow the
creation of new a new ClassLoader . |
---|
Sets the default assertion status for this class loader to false
and removes any package default and class assertion status settings.
Note: This method does nothing in the Android reference implementation.
Returns this class loader's parent.
null
.SecurityException | if a security manager exists and it does not allow to retrieve the parent class loader. |
---|
Returns the URL of the resource with the specified name. This
implementation first tries to use the parent class loader to find the
resource; if this fails then findResource(String)
is called to
find the requested resource.
resName | the name of the resource to find. |
---|
URL
object for the requested resource or null
if either the resource can not be found or a security manager
does not allow to access the resource.Returns a stream for the resource with the specified name. See
getResource(String)
for a description of the lookup algorithm
used to find the resource.
resName | the name of the resource to find. |
---|
null
if either the resource
can not be found or a security manager does not allow to access
the resource.Returns an enumeration of URLs for the resource with the specified name.
This implementation first uses this class loader's parent to find the
resource, then it calls findResources(String)
to get additional
URLs. The returned enumeration contains the URL
objects of both
find operations.
resName | the name of the resource to find. |
---|
URL
objects for the requested resource.IOException | if an I/O error occurs. |
---|
Returns the system class loader. This is the parent for new
ClassLoader
instances and is typically the class loader used to
start the application. If a security manager is present and the caller's
class loader is neither null
nor the same as or an ancestor of
the system class loader, then this method calls the security manager's
checkPermission method with a RuntimePermission("getClassLoader")
permission to ensure that it is ok to access the system class loader. If
not, a SecurityException
is thrown.
SecurityException | if a security manager exists and it does not allow access to the system class loader. |
---|
Finds the URL of the resource with the specified name. The system class loader's resource lookup algorithm is used to find the resource.
resName | the name of the resource to find. |
---|
URL
object for the requested resource or null
if the resource can not be found.Returns a stream for the resource with the specified name. The system class loader's resource lookup algorithm is used to find the resource. Basically, the contents of the java.class.path are searched in order, looking for a path which matches the specified resource.
resName | the name of the resource to find. |
---|
null
.Returns an enumeration of URLs for the resource with the specified name. The system class loader's resource lookup algorithm is used to find the resource.
resName | the name of the resource to find. |
---|
URL
objects containing the requested
resources.IOException | if an I/O error occurs. |
---|
Loads the class with the specified name. Invoking this method is
equivalent to calling loadClass(className, false)
.
Note: In the Android reference implementation, the
second parameter of loadClass(String, boolean)
is ignored
anyway.
className | the name of the class to look for. |
---|
Class
object.ClassNotFoundException | if the class can not be found. |
---|
Sets the assertion status of the class with the specified name.
Note: This method does nothing in the Android reference implementation.
cname | the name of the class for which to set the assertion status. |
---|---|
enable | the new assertion status. |
Sets the default assertion status for this class loader.
Note: This method does nothing in the Android reference implementation.
enable | the new assertion status. |
---|
Sets the assertion status of the package with the specified name.
Note: This method does nothing in the Android reference implementation.
pname | the name of the package for which to set the assertion status. |
---|---|
enable | the new assertion status. |
This method is deprecated.
Use defineClass(String, byte[], int, int)
Constructs a new class from an array of bytes containing a class definition in class file format.
classRep | the memory image of a class file. |
---|---|
offset | the offset into classRep . |
length | the length of the class file. |
Class
object created from the specified subset of
data in classRep
.ClassFormatError | if classRep does not contain a valid class. |
---|---|
IndexOutOfBoundsException | if offset < 0 , length < 0 or if
offset + length is greater than the length of
classRep . |
Defines a new class with the specified name, byte code from the byte
buffer and the optional protection domain. If the provided protection
domain is null
then a default protection domain is assigned to
the class.
name | the expected name of the new class, may be null if not
known. |
---|---|
b | the byte buffer containing the byte code of the new class. |
protectionDomain | the protection domain to assign to the loaded class, may be
null . |
Class
object created from the data in b
.ClassFormatError | if b does not contain a valid class. |
---|---|
NoClassDefFoundError | if className is not equal to the name of the class
contained in b . |
Constructs a new class from an array of bytes containing a class
definition in class file format and assigns the specified protection
domain to the new class. If the provided protection domain is
null
then a default protection domain is assigned to the class.
className | the expected name of the new class, may be null if not
known. |
---|---|
classRep | the memory image of a class file. |
offset | the offset into classRep . |
length | the length of the class file. |
protectionDomain | the protection domain to assign to the loaded class, may be
null . |
Class
object created from the specified subset of
data in classRep
.ClassFormatError | if classRep does not contain a valid class. |
---|---|
IndexOutOfBoundsException | if offset < 0 , length < 0 or if
offset + length is greater than the length of
classRep . |
NoClassDefFoundError | if className is not equal to the name of the class
contained in classRep . |
Constructs a new class from an array of bytes containing a class definition in class file format.
className | the expected name of the new class, may be null if not
known. |
---|---|
classRep | the memory image of a class file. |
offset | the offset into classRep . |
length | the length of the class file. |
Class
object created from the specified subset of
data in classRep
.ClassFormatError | if classRep does not contain a valid class. |
---|---|
IndexOutOfBoundsException | if offset < 0 , length < 0 or if
offset + length is greater than the length of
classRep . |
Defines and returns a new Package
using the specified
information. If sealBase
is null
, the package is left
unsealed. Otherwise, the package is sealed using this URL.
name | the name of the package. |
---|---|
specTitle | the title of the specification. |
specVersion | the version of the specification. |
specVendor | the vendor of the specification. |
implTitle | the implementation title. |
implVersion | the implementation version. |
implVendor | the specification vendor. |
sealBase | the URL used to seal this package or null to leave the
package unsealed. |
Package
object that has been created.IllegalArgumentException | if a package with the specified name already exists. |
---|
Overridden by subclasses, throws a ClassNotFoundException
by
default. This method is called by loadClass
after the parent
ClassLoader
has failed to find a loaded class of the same name.
className | the name of the class to look for. |
---|
Class
object that is found.ClassNotFoundException | if the class cannot be found. |
---|
Returns the absolute path of the native library with the specified name,
or null
. If this method returns null
then the virtual
machine searches the directories specified by the system property
"java.library.path".
This implementation always returns null
.
libName | the name of the library to find. |
---|
Returns the class with the specified name if it has already been loaded
by the virtual machine or null
if it has not yet been loaded.
className | the name of the class to look for. |
---|
Class
object or null
if the requested class
has not been loaded.Finds the URL of the resource with the specified name. This
implementation just returns null
; it should be overridden in
subclasses.
resName | the name of the resource to find. |
---|
URL
object for the requested resource.Finds an enumeration of URLs for the resource with the specified name.
This implementation just returns an empty Enumeration
; it should
be overridden in subclasses.
resName | the name of the resource to find. |
---|
URL
objects for the requested resource.IOException | if an I/O error occurs. |
---|
Finds the class with the specified name, loading it using the system class loader if necessary.
className | the name of the class to look for. |
---|
Class
object with the requested className
.ClassNotFoundException | if the class can not be found. |
---|
Returns the package with the specified name. Package information is searched in this class loader.
name | the name of the package to find. |
---|
null
if the package
can not be found.Returns all the packages known to this class loader.
Loads the class with the specified name, optionally linking it after loading. The following steps are performed:
findLoadedClass(String)
to determine if the requested
class has already been loaded.findClass(String)
to find the class.
Note: In the Android reference implementation, the
resolve
parameter is ignored; classes are never linked.
className | the name of the class to look for. |
---|---|
resolve | Indicates if the class should be resolved after loading. This parameter is ignored on the Android reference implementation; classes are not resolved. |
Class
object.ClassNotFoundException | if the class can not be found. |
---|
Forces a class to be linked (initialized). If the class has already been linked this operation has no effect.
Note: In the Android reference implementation, this method has no effect.
clazz | the class to link. |
---|
Sets the signers of the specified class. This implementation does nothing.
c | the Class object for which to set the signers. |
---|---|
signers | the signers for c . |