Created
December 2, 2014 15:42
-
-
Save glaforge/1f481e0f0d043260aa9a to your computer and use it in GitHub Desktop.
List and Map constructor coercion in Groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.transform.Immutable | |
@Immutable | |
class Point { | |
double x, y | |
} | |
Point p1 = [1.23, 5.67] | |
assert p1.x == 1.23 && p1.y == 5.67 | |
Point p2 = [y: 10, x: -1] | |
assert p2.x == -1 && p2.y == 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some further examples in MrHaki's blog post:
http://mrhaki.blogspot.nl/2009/09/groovy-goodness-using-lists-and-maps-as.html