@@ -39,13 +39,13 @@ public static int nextCapacity(int currentCapacity, int minCapacity) {
3939 return Math .max (growCap , minCapacity );
4040 }
4141
42- private final Class <?> primitiveClass ;
4342 private final Class <A > arrayClass ;
43+ private final Class <?> primitiveClass ;
4444 protected final A empty ;
4545
46- private ArrayAccessor (Class <?> primitiveClass , Class <A > arrayClass , A empty ) {
47- this .primitiveClass = primitiveClass ;
46+ private ArrayAccessor (Class <A > arrayClass , A empty ) {
4847 this .arrayClass = arrayClass ;
48+ this .primitiveClass = arrayClass .getComponentType ();
4949 this .empty = empty ;
5050 }
5151
@@ -64,6 +64,8 @@ public final Class<A> getArrayClass() {
6464
6565 public abstract A copyOf (A array , int newLength );
6666
67+ public abstract A newArray (int newLength );
68+
6769 public final int getLength (A array ) {
6870 return Array .getLength (array );
6971 }
@@ -86,7 +88,12 @@ public final int getLength(A array) {
8688
8789 public abstract T newTagFromElement (A array , int index );
8890
89- public static final ArrayAccessor <Byte , ByteTag , byte [], ByteBuffer > BYTE_ARRAY = new ArrayAccessor <>(byte .class , byte [].class , new byte [0 ]) {
91+ public static final ArrayAccessor <Byte , ByteTag , byte [], ByteBuffer > BYTE_ARRAY = new ArrayAccessor <>(byte [].class , new byte [0 ]) {
92+ @ Override
93+ public byte [] newArray (int newLength ) {
94+ return new byte [newLength ];
95+ }
96+
9097 @ Override
9198 public byte [] copyOf (byte [] array , int newLength ) {
9299 return Arrays .copyOf (array , newLength );
@@ -157,7 +164,12 @@ public ByteTag newTagFromElement(byte[] array, int index) {
157164 }
158165 };
159166
160- public static final ArrayAccessor <Integer , IntTag , int [], IntBuffer > INT_ARRAY = new ArrayAccessor <>(int .class , int [].class , new int [0 ]) {
167+ public static final ArrayAccessor <Integer , IntTag , int [], IntBuffer > INT_ARRAY = new ArrayAccessor <>(int [].class , new int [0 ]) {
168+
169+ @ Override
170+ public int [] newArray (int newLength ) {
171+ return new int [newLength ];
172+ }
161173
162174 @ Override
163175 public int [] copyOf (int [] array , int newLength ) {
@@ -229,7 +241,12 @@ public IntTag newTagFromElement(int[] array, int index) {
229241 }
230242 };
231243
232- public static final ArrayAccessor <Long , LongTag , long [], LongBuffer > LONG_ARRAY = new ArrayAccessor <>(long .class , long [].class , new long [0 ]) {
244+ public static final ArrayAccessor <Long , LongTag , long [], LongBuffer > LONG_ARRAY = new ArrayAccessor <>(long [].class , new long [0 ]) {
245+
246+ @ Override
247+ public long [] newArray (int newLength ) {
248+ return new long [newLength ];
249+ }
233250
234251 @ Override
235252 public long [] copyOf (long [] array , int newLength ) {
0 commit comments