#navi_header|Java| 参考: - https://twitter.com/benjiweber/status/633022519650451456 - GitHub - benjiman/lambda-type-references: Type References using Lambdas -- https://github.com/benjiman/lambda-type-references - Lambda Type References | Benji's Blog - -- https://benjiweber.co.uk/blog/2015/08/04/lambda-type-references/ - Java 8u60で、Mapの初期化とかがすごい楽になってる件 - mike-neckのブログ -- https://mike-neck.hatenadiary.com/entry/2015/08/21/034542 何ができるようになるか?: #pre||> @Test public void java_hash_literal() { Map hash = hash( hello -> "world", bob -> bob, bill -> "was here" ); assertEquals("world", hash.get("hello")); assertEquals("bob", hash.get("bob")); assertEquals("was here", hash.get("bill")); } public static Map hash(NamedValue... keyValuePairs) { Map map = new HashMap<>(); asList(keyValuePairs) .stream() .forEach(kvp -> map.put( kvp.name(), kvp.value()) ); return map; } ||< (via : https://github.com/benjiman/lambda-type-references/blob/master/src/test/java/com/benjiweber/HashLiteralExample.java ) なんとなくしか理解してないが、ラムダ式の引数名をリフレクションで取り出せるようになったのを活用して、key -> value をラムダ式に見立てれば、key をラムダ式の引数名として取り出せるよね、それでクールなMapビルダー作れたよ!という話らしい。 まぁ空白とか記号混じりは厳しそうなのである程度制限はあると思うが、アイデアとしては面白い。 ・・・まぁ、これ使うくらいならドメイン特化したビルダー作るかもしれないけど・・・。 #navi_footer|Java|