Below is my list defination.
static List<Integer> list = Arrays.asList(112, 323, 368, 369, 378);
The list is having fixed size as 5.
On calling a add like this
list.add(200);
Should not this be a compile time error ? Rather it threw below exception at runtime
java.lang.UnsupportedOperationException
We knew that Arrays.asList
returns a List
of fixed size backed by an array
of fixed length.
Now the compiler doesn't know the length of the array at compile time. unless you run the program, you don't know the length at runtime.
In short, you can't modify an array at compile time :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With