Returns a new array of the given length with the same type as a reference array. @param reference any array of the desired type @param length the length of the new array
(T[] reference, int length)
| 37 | * @param length the length of the new array |
| 38 | */ |
| 39 | static <T> T[] newArray(T[] reference, int length) { |
| 40 | Class<?> type = reference.getClass().getComponentType(); |
| 41 | |
| 42 | // the cast is safe because |
| 43 | // result.getClass() == reference.getClass().getComponentType() |
| 44 | @SuppressWarnings("unchecked") |
| 45 | T[] result = (T[]) Array.newInstance(type, length); |
| 46 | return result; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Configures the given map maker to use weak keys, if possible; does nothing |