I ran across this bit of code and to me it seems like its not needed is there any reason to do the following
def answers = [] as List
instead of
def answers = []
In groovy I thought that [] was the empty list so there would be no need to have the as List
A List literal is presented as a series of objects separated by commas and enclosed in square brackets. To process the data in a list, we must be able to access individual elements. Groovy Lists are indexed using the indexing operator []. List indices start at zero, which refers to the first element.
-> is a symbol indicating the end of parameters list for a closure in Groovy.
You can use the getClass() method to determine the class of an object. Also, if you want to check if an object implements an Interface or Class, you can use the instanceof keyword. That's it about checking the datatype of an object in Groovy.
No, there is no difference, both create an ArrayList
and List
(java.util.List
) is an interface anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With