0

I declare a typed variable like this:

List<String> listOfStrings = []

I add non-strings to my list:

listOfStrings.add(2)
lisOfStrings << UUID.fromString('754f998d-9eb8-4465-8e83-e16e0316701d')

Since I declared the type instead of using def, I would expect either a 'Cannot cast' exception or values being coerced to a String - ['2', '754f998d-9eb8-4465-8e83-e16e0316701d'].

However, the result is an ArrayList with an Integer and UUID objects. Why is that? And how can I enforce the type (without using toString for ever value added)?

0 Answers0