tags:

views:

42

answers:

1

This works perfectly if the priobann list is populated:

banns << priobann?.pop()

However, if it's empty, I get the exception: java.util.NoSuchElementException: Cannot pop() an empty List

Shouldn't the question mark after priobann avoid this exception ?

+1  A: 

No, the ? will only stop the method being called if the reference is null. In this case the reference is not null, but the object is refers to is an empty List.

Obviously, you can't call pop() on an empty List because there's nothing to remove.

Don