From: "John Leuner" <[EMAIL PROTECTED]>
> The method in vm/reference/java/lang/Class.java:
>
> public Class getComponentType() {
> if(isArray()) {
> try {
> return Class.forName(getName().substring(1));
> } catch(ClassNotFoundException e) {
> return null;
> }
> } else {
> return null;
> }
> }
>
> is wrong.
>
Very good catch. Definitely needs a test, too. The only thing it'll work
for right now is nested arrays.
I think it would be a lot easier (and more efficient) to parse in
Class.java. How's this?
(Source:
http://java.sun.com/products/jdk/1.1/docs/guide/jni/spec/types.doc.html#1643
2)
public Class getComponentType() {
if(isArray()) {
try {
String name = getName();
switch(name.charAt(1)) {
case "[":
return Class.forName(name.substring(1));
case "L":
return Class.forName(name.substring(2,
name.length()-1));
case "Z":
return Boolean.class;
case "B":
return Byte.class;
case "C":
return Character.class;
case "S":
return Short.class;
case "I":
return Integer.class;
case "J":
return Long.class;
case "F":
return Float.class;
case "D":
return Double.class;
}
} catch(ClassNotFoundException e) {
return null;
}
} else {
return null;
}
}
This is not even compiled but It Should Work (TM).
--John
_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath