de.spieleck.util
Class FastClassForName
java.lang.Object
|
+--de.spieleck.util.FastClassForName
- public class FastClassForName
- extends java.lang.Object
This is a replacement for Class.forName(...).newInstance().
It is fast.
In my bench it is much faster than the latter construct.
Efficient caching and loading mechanism to obtain classes
with a default constructor in the current ContextClassLoader.
It treats some classloader intricaties.
Field Summary |
protected static java.util.HashMap |
classCache
Keep track of all classes aquired for
faster second access. |
Method Summary |
static java.lang.Class |
contextClassForName(java.lang.String className,
java.lang.Class context)
Try to load a class from the right contextual classloader.
|
static java.lang.Object |
newInstance(java.lang.String className,
java.lang.Class require)
|
static java.lang.Object |
newInstance(java.lang.String className,
java.lang.String defaultPackage,
java.lang.Class require)
|
static java.lang.Object |
newInstance(java.lang.String className,
java.lang.String defaultPackage,
java.lang.Class require,
java.lang.Class context)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
classCache
protected static java.util.HashMap classCache
- Keep track of all classes aquired for
faster second access.
newInstance
public static java.lang.Object newInstance(java.lang.String className,
java.lang.Class require)
newInstance
public static java.lang.Object newInstance(java.lang.String className,
java.lang.String defaultPackage,
java.lang.Class require)
newInstance
public static java.lang.Object newInstance(java.lang.String className,
java.lang.String defaultPackage,
java.lang.Class require,
java.lang.Class context)
contextClassForName
public static java.lang.Class contextClassForName(java.lang.String className,
java.lang.Class context)
throws java.lang.ClassNotFoundException
- Try to load a class from the right contextual classloader.
The right classloader can be somewhat strange in an Ant or
Servlet context.