I was checking the implementation of IndexOutOfBoundsException in JDK 16, and I have noticed that a new constructor with a long index has been introduced:
/**
* Constructs a new {@code IndexOutOfBoundsException} class with an
* argument indicating the illegal index.
*
* <p>The index is included in this exception's detail message. The
* exact presentation format of the detail message is unspecified.
*
* @param index the illegal index.
* @since 16
*/
public IndexOutOfBoundsException(long index) {
super("Index out of range: " + index);
}
From what I know, array indices are usually int values, and this is confirmed in the Language Specification section §10.4:
Arrays must be indexed by
intvalues;short,byte, orcharvalues may also be used as index values because they are subjected to unary numeric promotion (§5.6) and becomeintvalues.
An attempt to access an array component with a
longindex value results in a compile-time error.
Any idea when (and why) this long index constructor would be used ?