as HashSet oddness

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

as HashSet oddness

Edward Povazan
Hello,

I am not even sure that this is supposed to work, but even if not things are
inconsistent:
def list = [1, 2] as ArrayList
println list
 >> [1, 2]

def list = [1, 2] as HashSet
println list
 >> [] // Empty?

Now for the fun part:
def list = [1, 2, 3] as HashSet
println list
 >> java.lang.ClassCastException: java.util.ArrayList // Add 3 and then this?

Why does the extra element throw this error? Odd no?
BTW, should this return a HashSet with elements [1, 2, 3] - it would be nice if
it did.

-Ed