optionally specify classloader to Class.forCanonicalName

This commit is contained in:
Joel Dice 2009-08-10 07:46:05 -06:00
parent 1a2deff97d
commit 97ea23e3bb

View File

@ -136,11 +136,15 @@ public final class Class <T> implements Type, GenericDeclaration {
private native void initialize();
public static Class forCanonicalName(String name) {
return forCanonicalName(null, name);
}
public static Class forCanonicalName(ClassLoader loader, String name) {
try {
if (name.startsWith("[")) {
return forName(name);
return forName(name, true, loader);
} else if (name.startsWith("L")) {
return forName(name.substring(1, name.length() - 1));
return forName(name.substring(1, name.length() - 1), true, loader);
} else {
if (name.length() == 1) {
return primitiveClass(name.charAt(0));