Skip to content

Instantly share code, notes, and snippets.

@glaforge
Created December 2, 2014 15:42
Show Gist options
  • Save glaforge/1f481e0f0d043260aa9a to your computer and use it in GitHub Desktop.
Save glaforge/1f481e0f0d043260aa9a to your computer and use it in GitHub Desktop.
List and Map constructor coercion in Groovy
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
@glaforge
Copy link
Author

glaforge commented Dec 2, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment