|
6 | 6 |
|
7 | 7 | import java.lang.reflect.Array;
|
8 | 8 | import java.util.ArrayList;
|
| 9 | +import java.util.Arrays; |
9 | 10 | import java.util.Collection;
|
10 | 11 | import java.util.List;
|
11 | 12 | import java.util.function.Consumer;
|
@@ -55,6 +56,14 @@ public static int indexOf(Object[] array, int end, Object object) {
|
55 | 56 | return -1;
|
56 | 57 | }
|
57 | 58 |
|
| 59 | + @SuppressWarnings("unchecked") |
| 60 | + @AllowReflection |
| 61 | + public static <T> T[] filledArray(T value, Class<T> valueJavaType, int size) { |
| 62 | + final T[] array = (T[]) Array.newInstance( valueJavaType, size ); |
| 63 | + Arrays.fill( array, value ); |
| 64 | + return array; |
| 65 | + } |
| 66 | + |
58 | 67 | public static String[] toStringArray(Object[] objects) {
|
59 | 68 | int length = objects.length;
|
60 | 69 | String[] result = new String[length];
|
@@ -335,4 +344,14 @@ public static <T> void forEach(T[] array, Consumer<T> consumer) {
|
335 | 344 | }
|
336 | 345 | }
|
337 | 346 | }
|
| 347 | + |
| 348 | + /** |
| 349 | + * @deprecated Use {@link Array#newInstance(Class, int)} instead. |
| 350 | + */ |
| 351 | + @Deprecated |
| 352 | + @SuppressWarnings("unchecked") |
| 353 | + @AllowReflection |
| 354 | + public static <T> T[] newInstance(Class<T> elementType, int length) { |
| 355 | + return (T[]) Array.newInstance( elementType, length ); |
| 356 | + } |
338 | 357 | }
|
0 commit comments