default set type in Groovy

println(([1] as Set).class)
do you know the class of this set. May be you think it's HashSet. The anwser is no, it's LinkedHashSet. That's to say it can keep insert order. I think it's convenient to use this as default. But you have to keep it in mind that this is not the most efficient choice. If you don't care insert order, you can use HashSet like this:
[1] as HashSet

你可能感兴趣的:(groovy)