(Object array, int index, Object value)
| 46 | } |
| 47 | |
| 48 | public static void set(Object array, int index, Object value) { |
| 49 | String className = array.getClass().getName(); |
| 50 | if (! className.startsWith("[")) { |
| 51 | throw new IllegalArgumentException(); |
| 52 | } |
| 53 | |
| 54 | switch (className.charAt(1)) { |
| 55 | case 'B': |
| 56 | ((byte[]) array)[index] = (Byte) value; |
| 57 | break; |
| 58 | case 'C': |
| 59 | ((char[]) array)[index] = (Character) value; |
| 60 | break; |
| 61 | case 'D': |
| 62 | ((double[]) array)[index] = (Double) value; |
| 63 | break; |
| 64 | case 'F': |
| 65 | ((float[]) array)[index] = (Float) value; |
| 66 | break; |
| 67 | case 'I': |
| 68 | ((int[]) array)[index] = (Integer) value; |
| 69 | break; |
| 70 | case 'J': |
| 71 | ((long[]) array)[index] = (Long) value; |
| 72 | break; |
| 73 | case 'S': |
| 74 | ((short[]) array)[index] = (Short) value; |
| 75 | break; |
| 76 | case 'Z': |
| 77 | ((boolean[]) array)[index] = (Boolean) value; |
| 78 | break; |
| 79 | case 'L': |
| 80 | case '[': |
| 81 | if (value == null |
| 82 | || array.getClass().getComponentType().isInstance(value)) |
| 83 | { |
| 84 | ((Object[]) array)[index] = value; |
| 85 | } else { |
| 86 | throw new IllegalArgumentException |
| 87 | ("need " + array.getClass().getComponentType() + |
| 88 | ", got " + value.getClass().getName()); |
| 89 | } |
| 90 | break; |
| 91 | |
| 92 | default: |
| 93 | throw new Error(); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | public static native int getLength(Object array); |
| 98 |
no test coverage detected