Given the code fragment:
What is the output?
A. The compilation fails.
B. [-1, -2, -3]
C. [-3, -2, -1]
D. A runtime exception is thrown.
Given the code fragment:
What is the output?
A. The compilation fails.
B. [-1, -2, -3]
C. [-3, -2, -1]
D. A runtime exception is thrown.
D)
Exception java.lang.UnsupportedOperationException
| at ImmutableCollections.uoe (ImmutableCollections.java:72)
| at ImmutableCollections$AbstractImmutableCollection.add (ImmutableCollections.java:76)
D – runtime
It’s runtime exception because the list obtained with List.of() is immutable. trying to add elements is not possible.
I’m getting runtime exception not compile time error