RuntimeClassFile
@Deprecated public class ClassInjector extends Object
Classes defined by ClassInjector may be unloaded, if no references to it exist. Once unloaded, they cannot be loaded again by name since the original bytecode was never preserved.
Debugging can be enabled via the java command-line option "-Dorg.cojen.util.ClassInjector.DEBUG=true". This causes all generated classes to be written to the temp directory, and a message is written to System.out indicating exactly where.
Modifier and Type | Method and Description |
---|---|
static ClassInjector |
create()
Deprecated.
Create a ClassInjector for defining one class.
|
static ClassInjector |
create(String prefix,
ClassLoader parent)
Deprecated.
Create a ClassInjector for defining one class.
|
static ClassInjector |
createExplicit(String name,
ClassLoader parent)
Deprecated.
Create a ClassInjector for defining one class with an explicit name.
|
Class |
defineClass(ClassFile cf)
Deprecated.
Define the new class from a ClassFile object.
|
String |
getClassName()
Deprecated.
Returns the name that must be given to the new class.
|
Class |
getNewClass()
Deprecated.
Returns the newly defined class.
|
OutputStream |
openStream()
Deprecated.
Open a stream to define the new class into.
|
public static ClassInjector create()
public static ClassInjector create(String prefix, ClassLoader parent)
If the parent loader was used for loading injected classes, the new class will be loaded by it. This allows auto-generated classes access to package accessible members, as long as they are defined in the same package.
prefix
- optional class name prefixparent
- optional parent ClassLoaderpublic static ClassInjector createExplicit(String name, ClassLoader parent)
If the parent loader was used for loading injected classes, the new class will be loaded by it. This allows auto-generated classes access to package accessible members, as long as they are defined in the same package.
name
- required class nameparent
- optional parent ClassLoaderIllegalArgumentException
- if name is nullpublic String getClassName()
public OutputStream openStream() throws IllegalStateException
IllegalStateException
- if new class has already been defined
or if a stream has already been openedpublic Class defineClass(ClassFile cf)
IllegalStateException
- if new class has already been defined
or if a stream has already been openedpublic Class getNewClass() throws IllegalStateException, ClassFormatError
IllegalStateException
- if class was never definedClassFormatError
Copyright © 2004-2015 Cojen. All Rights Reserved.