Video on new Collections APIs for Java 9 by @stuartmarks at #Devoxx
https://t.co/k21nNe2VW4
— Java (@java) 2015, 11æ 13
new Collections APIs for Java 9ã£ã¦ä½ããã£ã¦æãã ã£ããã§è©²å½ã®JEP 269ãèªãã§ã¿ããã¨ã«ããã
http://openjdk.java.net/jeps/269
JEP 269: Convenience Factory Methods for Collections
Owner Stuart Marks Created 2014/06/26 23:05 Updated 2015/11/05 22:58 Type Feature Status Proposed to Target Component core-libs/java.util:collections Scope SE Discussion core dash libs dash dev at openjdk dot java dot net Effort S Duration S Priority 3 Reviewed by Brian Goetz, Chris Hegarty, Paul Sandoz Endorsed by Brian Goetz Release 9 Issue 8048330
Summary
å°æ°ã®è¦ç´ ã«ããcollectionã¨mapã¤ã³ã¹ã¿ã³ã¹ã®çæã®æéã軽æ¸ããã©ã¤ãã©ãªAPIãå®ç¾©ãã¾ããç®çã¯Javaããã°ã©ãã³ã°è¨èªã«ã³ã¬ã¯ã·ã§ã³ãªãã©ã«ãç¡ããã¨ã«ããä¸ä¾¿ããç·©åãããã¨ã§ãã
Goals
ã³ã¬ã¯ã·ã§ã³ã®ã¤ã³ã¿ãã§ã¼ã¹ã«staticãã¡ã¯ããªã¼ã¡ã½ãããè¨ãããã®ã¤ã³ã¿ãã§ã¼ã¹ã¯ã³ã³ãã¯ã(compact)ã§æ´æ°ä¸è½ãª(unmodifiable)ã³ã¬ã¯ã·ã§ã³ã¤ã³ã¹ã¿ã³ã¹ãçæãã¾ããé »ç¹ã«ä½¿ãããã³ã¬ã¯ã·ã§ã³ã¯ã©ã¹ã®å®è£ ãçæããstaticãã¡ã¯ããªã¼ã¡ã½ãããæä¾ãã¾ãããã®APIã¯æå³çã«å°ããä¿ãããããã«ãã¾ãã
Non-Goals
ãã ããå®å ¨ã«æ±ç¨çãªã³ã¬ã¯ã·ã§ã³ãã«ãã¼("collection builder")æ©è½ã®æä¾ã¯æ¬JEPã®ç®çã§ã¯ããã¾ããããã¨ãã°ãã³ã¬ã¯ã·ã§ã³å®è£ ãã¦ã¼ã¶ãå¶å¾¡ãããããã¥ã¼ã¿ãã«ã»æå®ãµã¤ãºã»è² è·ç(loading factor)ã»ã³ã³ã«ã¬ã³ã·ã¼ã¬ãã«(concurrency level)ãªã©ã®æ©è½ããããã«å½ããã¾ãã
é«ããã©ã¼ãã³ã¹ããä»»æã®è¦ç´ æ°ã«ããã¹ã±ã¼ã©ãã«ãªã³ã¬ã¯ã·ã§ã³ã®ãµãã¼ãã対象å¤ã§ããæ¬JEPã¯å°è¦æ¨¡ãªã³ã¬ã¯ã·ã§ã³ã対象ã¨ãã¾ãã
æ´æ°ä¸è½ã³ã¬ã¯ã·ã§ã³å(unmodifiable collection types)ã®æä¾ã¯å¯¾è±¡å¤ã§ããæ¬JEPã§ã¯åã·ã¹ãã ã«ãããæ´æ°ä¸è½ã®æ©è½ãããã¨ãå®è£ ãå®éã«æ´æ°ä¸è½ã ã£ãã¨ãã¦ããå ¬éãã¾ããã
æ¬JEPã§ã¯"immutable persistent"ã"functional" collectionsã®æä¾ã¯è¡ãã¾ããã
Motivation
Javaã¯ãã®åé·ãã®ããã«æ¹å¤ã«æããããã¨ãããã¾ããå°æ°è¦ç´ ã§æ´æ°ä¸è½ãªã³ã¬ã¯ã·ã§ã³ãçæããã«ã¯ãã³ã¬ã¯ã·ã§ã³ãçæãããã¼ã«ã«å¤æ°ã«æ ¼ç´ããè¤æ°åadd()
ãå®è¡ããããããã©ãããã¾ãã
Set<String> set = new HashSet<>(); set.add("a"); set.add("b"); set.add("c"); set = Collections.unmodifiableSet(set);
ããã¯ãã¸ã§åé·ã§ããã®çç±ã¯åä¸ã®å¼ã§è¡¨ç¾ä¸å¯è½ã ããã§ããã¾ããstaticãªã³ã¬ã¯ã·ã§ã³ã¯ãããæ±ãããããã£ã¼ã«ãã¤ãã·ã£ã©ã¤ã¶ã§ã¯ãªããstaticã¤ãã·ã£ã©ã¤ã¶ã§ã®å¦çãå¿ é ã§ããå¥ã®æ¹æ³ã¨ãã¦ãä»ã®ã³ã¬ã¯ã·ã§ã³ãåãåãã³ãã¼ã³ã³ã¹ãã©ã¯ã¿ã使ç¨ããã³ã¬ã¯ã·ã§ã³å¦çã®ããæ¹ãããã¾ãã
Set<String> set = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("a", "b", "c")));
å¹¾åãã·ã§ã¯ããã¾ããã³ã¼ãã®æ確ããèãã¦ããããã¨ãã°Set
çæåã«List
ãçæãã¦ããç¹ãªã©ã§ããæ´ã«å¥ã®æ¹æ³ã¨ãã¦ããããã"double brace"ãã¯ããã¯ã使ãããæ¹ãããã¾ãã
Set<String> set = Collections.unmodifiableSet(new HashSet<String>() {{ add("a"); add("b"); add("c"); }});
ããã¯ç¡åå é¨ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã¤ãã·ã£ã©ã¤ã¶ã使ç¨ãã¦ããããããã·ã§ããããããããã¯ã¡ãã£ã¨åããã«ããã使ç¨æã«ä½åãªã¯ã©ã¹ã¨ããã³ã¹ããå¿ è¦ã§ããã¾ããã¨ã³ã¯ãã¼ã¸ã³ã°ã¤ã³ã¹ã¿ã³ã¹ã¸ã®é ãããåç §ã¨ãä»»æã®ãªãã¸ã§ã¯ãã¸ã®åç §ãä¿æãã¾ã*1ãããã¯ã¡ã¢ãªãªã¼ã¯ãã·ãªã¢ã©ã¤ãºæã«åé¡ãå¼ãèµ·ããå¯è½æ§ãããã¾ããããããçç±ã®ããããã®ãã¯ããã¯ã¯åºæ¬çã«ã¯é¿ããã¹ãã§ãã
Java 8 Stream APIã®ãã¡ã¯ããªã¡ã½ããã¨ã³ã¬ã¯ã¿ãçµã¿åããããã¨ã§ãå°è¦æ¨¡ãªã³ã¬ã¯ã·ã§ã³çæãå¯è½ã§ãã
Set<String> set = Collections.unmodifiableSet(Stream.of("a", "b", "c").collect(toSet()));
(streamã®ã³ã¬ã¯ã¿ã¯ãã³ã¬ã¯ã¿ãè¿ãã³ã¬ã¯ã·ã§ã³ã®ãã¥ã¼ã¿ãã«ã«ã¤ãã¦ã¯ä¿è¨¼ãã¾ãããJava 8ã§ã¯ãè¿ãããã³ã¬ã¯ã·ã§ã³ã¯ArrayList
, HashSet
, HashMap
ãªã©ã®ãã¥ã¼ã¿ãã«ã§é åºä»ãã®ã³ã¬ã¯ã·ã§ã³ã§ãããã ããå°æ¥ã®JDKãªãªã¼ã¹ã§å¤æ´ãããå¯è½æ§ãããã¾ãã)
ä¸è¨ã®ã³ã¼ãã¯è¥å¹²åããã©ããåããã«ããããã§ã¯ãªããã®ã®ãæ確ãªã³ã¼ãã¨ã¯ã¨ã¦ãè¨ãã¾ããããããã¾ãä¸å¿
è¦ãªãªãã¸ã§ã¯ãçæãããããå«ã¾ãã¦ãã¾ããç¾å¨ã®ã¨ããä¸è¨ã®æ¹æ³ã¯Map
ã«ã¯ä½¿ãã¾ãããStreamã§ã¯Map
çæã«ä¸è¨ã®ããæ¹ã¯ä½¿ç¨åºæ¥ã¾ããããã ããå¤ããã¼ããç®åºå¯è½ã§ããããstreamã®è¦ç´ ããã¼ã¨å¤ã®åæ¹ãå«ãå ´åã«ã¯å¯è½ã§ãã
ããã¾ã§ã«Javaããã°ã©ãã³ã°è¨èªã§ã³ã¬ã¯ã·ã§ã³ãªãã©ã«ããµãã¼ãããããã®å¤æ´æ¡ãä½åº¦ãæµ®ä¸ãã¦ãã¾ãããããããè¨èªæ©è½ã®å ´åã¨åæ§ãæåã«æãæãããã®ã»ã©ã¯ãªã¼ã³ã§ã·ã³ãã«ãªæ©è½ã«ã¯ãªããããã£ã¦ã³ã¬ã¯ã·ã§ã³ãªãã©ã«ãJavaã®æ¬¡æãã¼ã¸ã§ã³ã«ç¾ãããã¨ã¯ããã¾ããã§ããã
å°è¦æ¨¡ã³ã¬ã¯ã·ã§ã³ã¤ã³ã¹ã¿ã³ã¹çæç¨ã®ãªãã©ã«APIãæä¾ãããã¨ã§ã³ã¬ã¯ã·ã§ã³ãªãã©ã«ã®å©ç¹ã®å¤ããå®ç¾å¯è½ã§ãè¨èªå¤æ´ã«æ¯ã¹ãã°ãªã¹ã¯ã¨ã³ã¹ãã¯æ¥µãã¦ä½ãã§ããä¾ãã°ã以ä¸ã®ããã«ãã¦å°è¦æ¨¡ãªSet
ã¤ã³ã¹ã¿ã³ã¹ãçæããã³ã¼ããèãã¾ãã
Set<String> set = Set.of("a", "b", "c");
Collections
ã¯ã©ã¹ã«ã¯æ¢åã®ãã¡ã¯ããªã¡ã½ããã¨ãã¦ç©ºã®List
, Set
, Map
ãçæãããã®ãããã¾ããã¾ããåä¸ã®key-valueãã¢ããªãããåä¸è¦ç´ ã®ã¿ããæãã·ã³ã°ã«ãã³ã®List
, Set
, Map
ãçæãããã¡ã¯ããªãããã¾ããEnumSet
ã«ã¯åºå®ã¾ãã¯å¯å¤ã®å¼æ°ãåãof(...)
ã®ãªã¼ãã¼ãã¼ãã¡ã½ããããããæå®è¦ç´ ã§EnumSet
ãçæããéã«ä½¿ãã¾ããããããä»»æã®åã®ãªãã¸ã§ã¯ãããæãList
, Set
, Map
ãçæããããã®æ±ç¨ç®çã§ã¯ããã¾ããã
Collections
ã¯ã©ã¹ã«ã¯æ´æ°ä¸è½ãªList
, Set
, Map
ãçæããcombinatorã¡ã½ãããããã¾ãããããã®ã¡ã½ããã¯æ¬è³ªçã«ã¯æ´æ°ä¸è½ãªã³ã¬ã¯ã·ã§ã³ãçæãã¾ããã代ããã«ãã³ã¬ã¯ã·ã§ã³ãåãåãã¨æ´æ°ãªã¯ã¨ã¹ããæå¦ããã¯ã©ã¹ã§ã©ããããå
ã¨ãªãã³ã¬ã¯ã·ã§ã³ã®æ´æ°ä¸è½ãªãã¥ã¼(view)ãçæãã¾ããå
ã¨ãªãã³ã¬ã¯ã·ã§ã³ã¸ã®åç
§ãææãã¦ããã°æ´æ°æä½ã¯å¯è½ã§ããåã©ããã¼ã¯ãªãã¸ã§ã¯ããæ°è¦ä½æããã®ã§ãéæ¥æ¼ç®ãå¿
è¦ã¨ãªããå
ã¨ãªãã³ã¬ã¯ã·ã§ã³ã«ãã©ã¹ã®ã¡ã¢ãªæ¶è²»ãçºçãã¾ããã¾ãã決ãã¦æ´æ°ãçºçããªãå ´åã§ãã£ã¦ããã©ãããããã³ã¬ã¯ã·ã§ã³ã¯mutationã®ããã®ã³ã¹ããè² ãç¶ãããã¨ã«ãªãã¾ãã
Description
æ´æ°ä¸è½ãªã³ã¬ã¯ã·ã§ã³ã¤ã³ã¹ã¿ã³ã¹ãçæããããã«List
, Set
, Map
ã¤ã³ã¿ãã§ã¼ã¹ã«staticãã¡ã¯ããªã¡ã½ãããè¨ãã¾ããï¼ã¯ã©ã¹ã®staticã¡ã½ããã¨ã¯ç°ãªããã¤ã³ã¿ãã§ã¼ã¹ã®staticã¡ã½ããã¯ç¶æ¿ãããªãç¹ã«æ³¨æãã¦ãã ããããã£ã¦ãå®è£
ã¯ã©ã¹çµç±ã§ã¯å¼ã³åºããªãããã¤ã³ã¿ãã§ã¼ã¹åã®å®è£
çµç±ã§ãåæ§ã§ããï¼
List
ã¨Set
ã®ãã¡ã¯ããªã¼ã¡ã½ããã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
List.of(a, b, c); Set.of(d, e, f, g);
å¯å¤é·å¼æ°ã®ãªã¼ãã¼ãã¼ãããããããã³ã¬ã¯ã·ã§ã³ãµã¤ãºã«å¶éã¯ããã¾ããããã ããçæãããã³ã¬ã¯ã·ã§ã³ã¤ã³ã¹ã¿ã³ã¹ã®ãµã¤ãºãå°ãããã°ãã¥ã¼ãã³ã°ãå¯è½ãªå ´åãããã¾ããå°æ°è¦ç´ ç¨ã®ç¹æ®ã±ã¼ã¹APIï¼åºå®å¼æ°ã®ãªã¼ãã¼ãã¼ãï¼ãæä¾ãã¾ãã
Map
ã§ã¯åºå®å¼æ°ã®ã¡ã½ãããããã¤ãæä¾ãã¾ãã
Map.of()
Map.of(k1, v1)
Map.of(k1, v1, k2, v2)
Map.of(k1, v1, k2, v2, k3, v3)
...
æã
ã®æ³å®ã§ã¯8åã¾ã§ã®key-valueãã¢ã«ããmapçæã§å¤§æµã¯äºè¶³ããã§ãããã¨èãã¦ãã¾ãããã以ä¸ã®å ´åãä»»æã®æ°ã®key-valueãã¢ãæå®ãã¦Map
ã¤ã³ã¹ã¿ã³ã¹ãçæããAPIãæä¾ãã¾ãã
Map.fromEntries(Map.Entry<K,V>...)
ãã®ã¢ããã¼ãã¯List
ã¨Set
ç¨ã®å¯å¤é·å¼æ°APIã¨ä¼¼ã¦ã¯ãã¾ãããmapã¯ããã«ãã¨key-valueã®çµãå¿
è¦ã¨ãã¾ã*2ãkey-valueç¨ã®ã¡ã½ããã«ã¯static importãé©ãã¦ãããããã§ããç°¡æ½ã«ãªãã¾ãã
Map.Entry<K,V> entry(K k, V v)
ä¸è¨ã®ã¡ã½ããã使ç¨ãã¦ãä»»æã®æ°ã®è¦ç´ ãããªãmapãçæã§ãã¾ãã
Map.fromEntries(
entry(k1, v1),
entry(k2, v2),
entry(k3, v3),
// ...
entry(kn, vn));
ï¼å°æ¥ã®JDKãã¼ã¸ã§ã³ã§ã¯value typeã使ç¨ãããã¨ã§boxing*3ã®ã³ã¹ãã軽æ¸åºæ¥ãå¯è½æ§ãããã¾ããentry()
ç°¡æã¡ã½ããã®æ»ãå¤åã¯Map.Entry
ãå®è£
ããæ°è¦è¿½å ã®åã®äºå®ã§ããã®æªç½®ã¯å°æ¥çã«value typeã¸ã®ç§»è¡ãåæ»ã«ããããã®ãã®ã§ããï¼
å°è¦æ¨¡ã³ã¬ã¯ã·ã§ã³ãçæããAPIãæä¾ããã¾ããæ´æ°ä¸è½ã³ã¬ã¯ã·ã§ã³ã§ã¦ã¼ã¹ã±ã¼ã¹ã®å¤§åãæºãããã¨ã«ãããä»æ§ã¨å®è£ ã¯ã·ã³ãã«ã«ä¿ã¦ã¾ããæ´æ°ä¸è½ã³ã¬ã¯ã·ã§ã³ã¯é²å¾¡çã³ãã¼ãããªãã¦ãè¯ãããããã©ã¬ã«å¦çã«é©ãã¦ãã¾ãã
å°è¦æ¨¡ã³ã¬ã¯ã·ã§ã³ãå æããå®è¡æã®ç©ºéãã¾ãéè¦ãªèæ
®äºé
ã§ãã2ã¤ã®è¦ç´ ããæãæ´æ°ä¸è½HashSet
ã®çæã¨ããåç´ãªã±ã¼ã¹ã§ã©ããã¼APIã使ç¨ããã¨6åã®ãªãã¸ã§ã¯ããæ§æãã¾ããã©ããã¼ã»HasthSet
ã»HasthSet
å
ã®HashMap
ã»ãã±ããï¼é
åï¼ã®ãã¼ãã«ã»è¦ç´ ãã¨ã«1ã¤ã®Node
ã¤ã³ã¹ã¿ã³ã¹ãæ ¼ç´ãããã¼ã¿éã«æ¯ã¹ã¦åã¾ããéã®ãªã¼ãã¼ããããä¸ä¹ãããã¦ããããã¼ã¿ã¸ã®ã¢ã¯ã»ã¹ã«ãã¤ã³ã¿åç
§ã¨ã¡ã½ããå¼ã³åºããè¤æ°åå¿
è¦ã¨ãªãäºãé¿ãããã¾ãããå°è¦æ¨¡ã»åºå®ãµã¤ãºã³ã¬ã¯ã·ã§ã³ç¨ã«è¨è¨ããå®è£
ã¯ãããã®ãªã¼ãã¼ãããã®å¤§åãåé¿å¯è½ã§ãããã«ã¯ã³ã³ãã¯ããªãã£ã¼ã«ããã¼ã¹ãããã¯é
åãã¼ã¹ã®ã¬ã¤ã¢ã¦ãã使ç¨ãã¾ããmutationããµãã¼ãããå¿
è¦ãç¡ããã¨ï¼ã¨ãçææã«ã³ã¬ã¯ã·ã§ã³ãµã¤ãºãæ¢ç¥ã§ãããã¨ï¼ã空éã®ç¯ç´ã«å¯ä¸ãã¦ãã¾ãã
ãã¡ã¯ããªãè¿ãå®éã®ã¯ã©ã¹ã¯public APIãå ¬éãã¾ãããå®è¡æã®åãæ»ãããã³ã¬ã¯ã·ã§ã³ã®åä¸æ§(identity)ã«ã¤ãã¦ã®ä¿è¨¼ã¯ããã¾ãããããã«ãããäºææ§ãå£ããã¨ãªãå¾ã«ãªã£ã¦ããã®å®è£ å¤æ´ãå¯è½ã«ãªãã¾ããå¼ã³åºãå ãä¾åãã¹ããã¨ã¯ãæ»ãããåç §ãã¤ã³ã¿ãã§ã¼ã¹åã®å®è£ ã§ãããã¨ãããã¨ã ãã§ãã
è¿ããããªãã¸ã§ã¯ãã¯serializableã§ããA serialization proxy object will be used as the common serialized form for the implementation classes. ããã«ãããã·ãªã¢ã©ã¤ãºå½¢å¼ã«å®è£ ã®æ å ±ãæ¼ãåºã¦ãã¾ããã¨ãé²æ¢ãã¾ãããã®ãããªå°æ¥ã®ã¡ã³ããã³ã¹åãã®æè»æ§ãè¨ãããã¨ã«ãããã·ãªã¢ã©ã¤ãºã®äºææ§ã«å½±é¿ãä¸ãããã¨ãªãè¤æ°ã®ãªãªã¼ã¹ãã¾ããã§å®è£ ã«å¤æ´ãå ¥ãããã¨ãå¯è½ã¨ãªãã¾ãã
Nullã®è¦ç´ ã»ãã¼ã»å¤ã¯è¨±å®¹ãã¾ãããï¼ç´è¿ã§å°å ¥ãããã³ã¬ã¯ã·ã§ã³ã«nullããµãã¼ããããã®ã¯ããã¾ãããï¼ã¾ããnullæå¦ã«ãããããã«ã³ã³ãã¯ããªå é¨è¡¨ç¾ã»é«éã¢ã¯ã»ã¹ã»å°æ°ã®ç¹æ®ã±ã¼ã¹åãç¹åå®è£ ãã®å¯è½æ§ãçã¾ãã¾ãã
List
å®è£
ã¯ã¤ã³ããã¯ã¹ã«ããé«éè¦ç´ ã¢ã¯ã»ã¹ãæå¾
ããããããRandomAccess
ãã¼ã«ã¼ã¤ã³ã¿ã¼ãã§ã¼ã¹ãå®è£
ãã¾ãã
ã³ã¬ã¯ã·ã§ã³ã«æ ¼ç´ããè¦ç´ ã¯é常ã®ã³ã¬ã¯ã·ã§ã³ã®å¥ç´ã«å¾ããã¨ãå¿
é ã§ããããã®å¥ç´ã«ã¯é©åãªhashCode()
ã¨equals()
ã®å®è£
ãããã¾ããããhashCode()
ãequals()
ã«å½±é¿ãä¸ãããããªå¤æ´ãSet
ã®è¦ç´ ãããã¯Map
ã®ãã¼ã«å ããããå ´åãã³ã¬ã¯ã·ã§ã³ã®æ¯ãèãã¯æªå®ç¾©ã§ãã
ã³ã¬ã¯ã·ã§ã³ãçæãã¦å®å ¨ã«ãããªãã·ã¥ããã¦ä»¥éã¯ããã®ã¤ã³ã¹ã¿ã³ã¹ã¯è¤æ°ã¹ã¬ããã§ã³ã³ã«ã¬ã³ãã¢ã¯ã»ã¹ãå®å ¨ã«å®è¡ã§ãã¾ãã
é »ç¹ã«ä½¿ãããã³ã¬ã¯ã·ã§ã³ã¯ã©ã¹ç¨ã®ãã¡ã¯ããªã¼ã¡ã½ããã追å ãã¾ããå°ãªãã¨ãã以ä¸ã®ãããªã¡ã½ããã追å ãã¾ãã
ArrayList.of(...) HashSet.of(...) HashMap.of(...) HashMap.fromEntries(...)
ä¸è¨ã®ãã¡ã¯ããªã¼ã¡ã½ããã¯ç¹å®ã®ã³ã¬ã¯ã·ã§ã³ã®ã¤ã³ã¹ã¿ã³ã¹ãç°¡åã«ä½æãããã®ã§ããåºå®å¼æ°ã¨å¯å¤é·å¼æ°ã®ã¡ã½ããããããã¤ã³ã¿ãã§ã¼ã¹åã«è¿½å ããã¡ã½ããã¨ä¼¼ããããªæãã§ãã
JDKã§æ°APIã使ç¨å¯è½ãªå ´æã調æ»ä¸ã§ããæéã¨ã¹ã±ã¸ã¥ã¼ã«ã許ãã°æ°APIã使ç¨ãããããªå¤æ´ãè¡ãã¾ãã
Alternatives
éå»ã«è¨èªã«å¯¾ããå¤æ´ãä½åº¦ãè°è«ããããã®ã®ãå´ä¸ããã¦ãã¾ãã
- Project Coin Proposal, 29 March 2009
- Project Coin Proposal, 30 March 2009
- JEP 186 discussion on lambda-dev, January-March 2014
ãã®ã¡ãã»ã¼ã¸ã«è¦ç´ããã¦ããéããè¨èªãã¼ã¹ã®å¤æ´ææ¡ã§ã¯ãªãã©ã¤ãã©ãªãã¼ã¹ã®ææ¡ãæ¡ç¨ã¨ãªãã¾ããã
Google Guavaã©ã¤ãã©ãªã«ã¯ãã¤ãã¥ã¼ã¿ãã«ã³ã¬ã¯ã·ã§ã³çæç¨ã»ãã«ãã¼ãã¿ã¼ã³ã»æ§ã ãªãã¥ã¼ã¿ãã«ãªã³ã¬ã¯ã·ã§ã³ç¨ãã®ã¦ã¼ãã£ãªãã£ãããã¾ããGuavaã©ã¤ãã©ãªã¯å¤§å¤ä½¿ããããæ±ç¨çã§ãããJava SEãã©ãããã©ã¼ã ã«å«ããã«ã¯ã¡ãã£ã¨ã°ããããéã(overkill)ãªã·ãã¢ãã§ããæ¬JEPã®ææ¡ã¯Stephen Colebourneã®lambda-dev, 19 Feb 2014ã®ææ¡ã¨è¯ãä¼¼ã¦ãããã¾ããGuavaã®ã¤ãã¥ã¼ã¿ãã«ã³ã¬ã¯ã·ã§ã³ã®ãã¡ã¯ããªã¼ã¡ã½ããã®ã¢ã¤ãã¢ãåãå ¥ãã¦ãã¾ãã
Map.fromEntries()
ã¨ããä»»ææ°ã®è¦ç´ ã§Map
ãåæåããããæ¹ã¯çæ³çã§ã¯ç¡ãã§ããã代æ¿æ¡ã®ä¸ã§ã¯æããã·ãªãã®ãã¨æããã¾ããããã®å©ç¹ã¯ã¿ã¤ãã»ã¼ãã§ãæ§æä¸keyã¨valueãã¯ã³ã»ããã«æ¸ãã¦*4ãè¦ç´ æ°ãã³ã³ãã¤ã«æã«æ±ºã¾ãããã£ã¼ã«ãã¤ãã·ã£ã©ã¤ã¶ã¨ãã¦ã®ä½¿ãæ¹ã«ããããã¾ãããã ããboxingãªç¹ã¯åé·ã§ããè¤æ°ã®ä»£æ¿æ¡ãæ¤è¨ããã¾ãããããããã¯æ¬JEPã®ææ¡ãããè¯ããªããã¬ã¼ããªããçºçããããã®ã§ããã
Testing
JDKã¬ã°ã¬ãã·ã§ã³ãã¹ãã¹ã¤ã¼ãããã³public APIç¨ã®JDKãã¹ãã«ã¦ããããã¹ããåå¨ãã¾ããã·ãªã¢ã©ã¤ãºå½¢å¼ã¯JCKã§ã«ãã¼å¯è½ã¨æããã¾ãã
ãµã¤ãºããã³ããã©ã¼ãã³ã¹ãã¹ããä½æãã¾ããbaseline measurementsã¨ã®æ¯è¼ã¨ããä¸è¬çãªç®çã¨ã¯å¯¾ç §çã«ãæ°è¦ã®ã³ã¬ã¯ã·ã§ã³å®è£ ã¨æ¢åã®ãã®ã¨ãæ¯è¼ãããã¹ãã¨ãªãã¾ããåºå®ãªã¼ãã¼ããããã¼ã¹ã¨è¦ç´ å¥ãã¼ã¹ããããã«ããã¦ãæ°è¦ã³ã¬ã¯ã·ã§ã³ããã¼ã空éã®æ¶è²»ãå°ãªããããã¨ãæ¤è¨¼ãã¾ããæ¢åã³ã¬ã¯ã·ã§ã³ã¨æ¯è¼ããã¨ç°ãªãå é¨è¡¨ç¾ã¨ãªãã®ã§ãå ´åã«ãã£ã¦ã¯ãæ°è¦ã³ã¬ã¯ã·ã§ã³ã¯é ããªãå¯è½æ§ãããã¾ããããããã¹ãã¼ãã¦ã³ã¯è¨±å®¹ç¯å²å ã«åã¾ãã¹ãã§ããããã©ã¼ãã³ã¹ç®æ¨ã¯æ確ã«æå®ãã¦ãã¾ãããã10åé ããªããã¨ã¯è¨±å®¹ãã¾ãããã¾ããæ°è¦ã³ã¬ã¯ã·ã§ã³ã¯è¦ç´ æ°ã®å¢å ã«å¿ããä¸è²«æ§ã®ããããã©ã¼ãã³ã¹ãç¶æãã¾ããæå¾ã«ããã®ãã¹ãã®æ¸¬å®çµæã¯ããã©ã¼ãã³ã¹æ°å¤ã®ãã¼ã¹ã©ã¤ã³ãå®ãããã¨ã«ãªããå°æ¥ã®å¤æ´æã¨ã®æ¯è¼å¯¾è±¡ã¨ãªãã¾ãã
*1:and to any captured objects.ãåæã
*2:it unfortunately requires that each key-value pair be boxed.ãåæ
*3:ããªããã£ãã®ãã¯ã·ã³ã§ã¯ç¡ãã¨æãããListãsetã¨æ¯ã¹ãã¨ãMapã¯åãåãè¦ç´ ãåä¸ã§ã¯ãªãkey-valueãã¢ã«ãªããã§ãfromEntriesã§ã¯key-valueã®ãã¢ãåãåããããã®ãã¢ãentry()ã§å²ããã¨ãboxã¨è¨ã£ã¦ãã®ããªï¼ã¨æ¨æ¸¬ãã¦ããã
*4:it has keys and values adjacent in the syntaxãåæãææ³ä¸key-valueãé£æ¥ããã¦æ¸ããå©ç¹ããããã¨è¨ã£ã¦ããã¨æãã®ã§ã¡ãã£ã¨æ訳ãã