139 |
* accepts both object and descriptor formats, but must know which style |
* accepts both object and descriptor formats, but must know which style |
140 |
* of string is being passed in (usually, descriptor should be true). In |
* of string is being passed in (usually, descriptor should be true). In |
141 |
* descriptor format, "I" is treated as int.class, in object format, it |
* descriptor format, "I" is treated as int.class, in object format, it |
142 |
* is treated as a class named I in the unnamed package. |
* is treated as a class named I in the unnamed package. This method is |
143 |
|
* strictly equivalent to {@link #getClassForEncoding(java.lang.String, boolean, java.lang.ClassLoader)} |
144 |
|
* with a class loader equal to <code>null</code>. In that case, it |
145 |
|
* uses the default class loader on the calling stack. |
146 |
* |
* |
147 |
* @param type_code the class name to decode |
* @param type_code the class name to decode |
148 |
* @param descriptor if the string is in descriptor format |
* @param descriptor if the string is in descriptor format |
153 |
public static Class getClassForEncoding(String type_code, boolean descriptor) |
public static Class getClassForEncoding(String type_code, boolean descriptor) |
154 |
throws ClassNotFoundException |
throws ClassNotFoundException |
155 |
{ |
{ |
156 |
|
return getClassForEncoding(type_code, descriptor, null); |
157 |
|
} |
158 |
|
|
159 |
|
/** |
160 |
|
* This function is the inverse of <code>getEncodingOfClass</code>. This |
161 |
|
* accepts both object and descriptor formats, but must know which style |
162 |
|
* of string is being passed in (usually, descriptor should be true). In |
163 |
|
* descriptor format, "I" is treated as int.class, in object format, it |
164 |
|
* is treated as a class named I in the unnamed package. |
165 |
|
* |
166 |
|
* @param type_code The class name to decode. |
167 |
|
* @param descriptor If the string is in descriptor format. |
168 |
|
* @param loader The class loader when resolving generic object name. If |
169 |
|
* <code>loader</code> is null then it uses the default class loader on the |
170 |
|
* calling stack. |
171 |
|
* @return the corresponding Class object. |
172 |
|
* @throws ClassNotFoundException if the class cannot be located. |
173 |
|
* @see #getEncodingOfClass(Class, boolean) |
174 |
|
* @see #getClassForEncoding(String, boolean) |
175 |
|
*/ |
176 |
|
public static Class getClassForEncoding(String type_code, boolean descriptor, ClassLoader loader) |
177 |
|
throws ClassNotFoundException |
178 |
|
{ |
179 |
if (descriptor) |
if (descriptor) |
180 |
{ |
{ |
181 |
switch (type_code.charAt(0)) |
switch (type_code.charAt(0)) |
207 |
case '[': |
case '[': |
208 |
} |
} |
209 |
} |
} |
210 |
return Class.forName(type_code.replace('/', '.')); |
return Class.forName(type_code.replace('/', '.'), true, loader); |
211 |
} |
} |
212 |
|
|
213 |
/** |
/** |