Unable to append to an array of G4P objects

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: :wink:

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;
}
2 Likes