Last active
September 23, 2015 21:37
-
-
Save nobeans/619334 to your computer and use it in GitHub Desktop.
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
// g100pon #57 GStringが遅延評価ぽくなるケース | |
String s1 = "こんにちは" | |
String s2 = "g100pon" | |
def gstrFixed = "${s1}、${s2}です" // 文字列としてGStringに埋め込むのでこの時点で確定している | |
def gstrLazy = "${->s1}、${->s2}です" // Closureでくるむことで評価を遅延させる | |
assert gstrFixed.toString() == "こんにちは、g100ponです" | |
assert gstrLazy.toString() == "こんにちは、g100ponです" | |
s1 = "こんばんは" | |
s2 = "g1000bon" | |
assert gstrFixed.toString() == "こんにちは、g100ponです" | |
assert gstrLazy.toString() == "こんばんは、g1000bonです" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment