Created
February 12, 2015 04:53
-
-
Save elucash/8542f28198ca571dd666 to your computer and use it in GitHub Desktop.
Thinking of ADT-like support for Immutables. Case matching using Java8
This file contains hidden or 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
interface Q {} | |
@Value.Immutable | |
interface A extends Q{} | |
@Value.Immutable | |
interface B extends Q{} | |
@Value.Immutable | |
interface C extends Q{ int x(); int y(); int z(); } | |
int result = match(q) | |
.caseA(a -> computeWithA(a)) | |
.caseB(b -> computeWithB(b)) | |
.caseC((x, y, z) -> compute(x, y, z)) // this overload takes destructured attributes | |
.result(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment