groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Winnebeck, Jason" <Jason.Winneb...@windstream.com>
Subject Collection/Map Casting
Date Tue, 28 Apr 2015 18:16:29 GMT
Is there an elegant way to cast a collection's types?

[1,2,3] as List<String> //doesn't actually work
[1,2,3].collect { it as String } //works but more verbose

[a:1, b:2].collectEntries { k,v -> [k, v as String] } //is there a better way?

The other issue with collectEntries is that the @CompileStatic doesn't know the type returned,
so you have to actually cast it twice.

Jason

----------------------------------------------------------------------
This email message and any attachments are for the sole use of the intended recipient(s).
Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the
intended recipient, please contact the sender by reply email and destroy all copies of the
original message and any attachments.

Mime
View raw message