2007-07-21 20:44:39 +00:00
|
|
|
package java.lang.reflect;
|
|
|
|
|
|
|
|
public final class Array {
|
|
|
|
private Array() { }
|
|
|
|
|
2007-07-27 02:39:53 +00:00
|
|
|
public static native Object get(Object array, int index);
|
|
|
|
|
2007-07-27 23:56:19 +00:00
|
|
|
public static native void set(Object array, int index, Object value);
|
|
|
|
|
2007-07-27 02:39:53 +00:00
|
|
|
public static native int getLength(Object array);
|
|
|
|
|
|
|
|
private static native Object makeObjectArray(Class elementType, int length);
|
|
|
|
|
|
|
|
public static Object newInstance(Class elementType, int length) {
|
|
|
|
if (length < 0) {
|
|
|
|
throw new NegativeArraySizeException();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (elementType.equals(boolean.class)) {
|
|
|
|
return new boolean[length];
|
|
|
|
} else if (elementType.equals(byte.class)) {
|
|
|
|
return new byte[length];
|
|
|
|
} else if (elementType.equals(char.class)) {
|
|
|
|
return new char[length];
|
|
|
|
} else if (elementType.equals(short.class)) {
|
|
|
|
return new short[length];
|
|
|
|
} else if (elementType.equals(int.class)) {
|
|
|
|
return new int[length];
|
|
|
|
} else if (elementType.equals(long.class)) {
|
|
|
|
return new long[length];
|
|
|
|
} else if (elementType.equals(float.class)) {
|
|
|
|
return new float[length];
|
|
|
|
} else if (elementType.equals(double.class)) {
|
|
|
|
return new double[length];
|
|
|
|
} else {
|
|
|
|
return makeObjectArray(elementType, length);
|
|
|
|
}
|
|
|
|
}
|
2007-07-21 20:44:39 +00:00
|
|
|
}
|