(Class elementType, int length)
| 99 | private static native Object makeObjectArray(Class elementType, int length); |
| 100 | |
| 101 | public static Object newInstance(Class elementType, int length) { |
| 102 | if (length < 0) { |
| 103 | throw new NegativeArraySizeException(); |
| 104 | } |
| 105 | |
| 106 | if (elementType.isPrimitive()) { |
| 107 | if (elementType.equals(boolean.class)) { |
| 108 | return new boolean[length]; |
| 109 | } else if (elementType.equals(byte.class)) { |
| 110 | return new byte[length]; |
| 111 | } else if (elementType.equals(char.class)) { |
| 112 | return new char[length]; |
| 113 | } else if (elementType.equals(short.class)) { |
| 114 | return new short[length]; |
| 115 | } else if (elementType.equals(int.class)) { |
| 116 | return new int[length]; |
| 117 | } else if (elementType.equals(long.class)) { |
| 118 | return new long[length]; |
| 119 | } else if (elementType.equals(float.class)) { |
| 120 | return new float[length]; |
| 121 | } else if (elementType.equals(double.class)) { |
| 122 | return new double[length]; |
| 123 | } else { |
| 124 | throw new IllegalArgumentException(); |
| 125 | } |
| 126 | } else { |
| 127 | return makeObjectArray(elementType, length); |
| 128 | } |
| 129 | } |
| 130 | } |
no test coverage detected