Groovy: Create unmodifiable list
We can also use asImmutable()
method on list to make an unmodifiable list.
// Create List that is unmodifiable.
def list = ["Sun", "Earth", "Pluto", "Jupiter"].asImmutable()
// This will throw UnsupportedOperationException when try to modify the list
list << "Summary"