Using (cast)
is indeed not ideal. If you wish, you can override append() pasting the 3 methods below on your sketch, so (cast)
isn’t needed anymore:
static final <T> T[] expand(final T[] list) {
return expand(list, list.length << 1);
}
static final <T> T[] expand(final T[] list, final int newSize) {
return java.util.Arrays.copyOf(list, newSize);
}
static final <T> T[] append(final T[] list, final T value) {
final T[] arr = expand(list, list.length + 1);
arr[arr.length - 1] = value;
return arr;
}