Is there some way I can prove (i.e., write a test ...
# announcements
k
Is there some way I can prove (i.e., write a test case to show) that the list returned by
listOf(...)
is immutable (er, unmodifiable)? I tried to use reflection to list the functions on the resulting object, but all the
add
,
remove
, etc, methods are still there.
k
As per the list interface there is no way to test this.
You can try calling all of the modifying functions and see if any of them throw.
(no that you need to call all of them because implementations of List can for example allow
set(index, value)
while throwing for
add(value)
. (see Arrays.asList)
d
Hmm, can you replace with a wrapper class that internally uses an immutable list?
Seems like overkill but if you gotta be sure...