å
ææ«ã§JDK11ã¯Rampdownãã§ã¼ãºã«å
¥ã£ã¦ãæ©è½åçµããã¾ããã
ãªã®ã§ãä»å¾ã¯APIã®è¿½å ã»åé¤ã»å¤æ´ã¯ã»ã¨ãã©ãªãã¨æããã¾ãã
ãããããæ©è½çã«ã¯ç¾å¨ã§ã¦ããea20ã¨ã»ã¨ãã©åããã®ãJava11ã¨ãã¦ãªãªã¼ã¹ããããã¨ã«ãªãã¨æãã¾ãã
JDK 11 Early-Access Builds
大ããªæ©è½å¤æ´ã¨ãã¦ã¯ãããã§JEPã¨ãã¦ã¾ã¨ã¾ã£ã¦ãã¾ãã
ãJDK 11ã http://openjdk.java.net/projects/jdk/11/
Raw String Literalãéã«åããªãã£ãã®ã¯ã¨ã¦ãæ®å¿µã§ããJDK11ãã¬ã¤ã³ã«ä¹ãé
ããããããã°ããï¼ã¿ãããªæ稿ããã£ã¦ä»æ§ãã¾ã¨ãã¦ããMLä¸ã¯é³æ²æ±°ãªãã§ãããRampdownãã§ã¼ãºãå§ã¾ã£ã¦ããæ©è½è¿½å ããLate Enhancement Request Processã¨ããã®ããããããªã®ã§ãããã«è³ãã¾ãããã
JEP 3: JDK Release Process
Switch Expressionã¯Release 12ã¨ã¿ã¼ã²ãããæè¨ããã¦ãã¾ãããRaw String Literals㯠ã¾ã ã¿ã¼ã²ãããæè¨ããã¦ãããã11ã«å
¥ãããã¨ã諦ããããã§ã¯ãªãã¨ãä¸ç¸·ã®æã¿ãã
JEP 325: Switch Expressions
JEP 326: Raw String Literals
ã¨ããããJDK11ã§ã¯JEPã«ããããã¦ãã以å¤ã®å¤æ´ãå¤ãå
¥ã£ã¦ãã¾ããããã§ããã¾å人çã«ææ¡ãã¦ããç¯å²ã§ã®APIå¤æ´ãåæãã¦ããã¾ãã
String
repeat(int)
æååãæå®ããåæ°ç¹°ãè¿ãã¾ãã
jshell> "test".repeat(3) $7 ==> "testtesttest"
isBlank()
空ç½ã ããã©ãããå¤å®ããã¡ã½ããã追å ããã¾ãããå ¨è§ã¹ãã¼ã¹ã空ç½ã¨ãã¦å¤å®ããã¾ãã
jshell> var halfSpace = "\u0020" halfSpace ==> " " jshell> halfSpace.isBlank() $11 ==> true jshell> var fullSpace = "\u3000" fullSpace ==> "ã" jshell> fullSpace.isBlank() $13 ==> true
strip() / stripLeading() / stripTrailing()
trim() / trimLeft() / trimRight() ã¨ã»ã¼åãå½¹å²ãªã®ã§ãããå ¨è§ã¹ãã¼ã¹ãªã©ã空ç½ã¨ã¿ãªãããã¨ãããéãã¾ãã
jshell> var aaa = fullSpace + "aaa" + fullSpace aaa ==> "ãaaaã" jshell> aaa.strip() $14 ==> "aaa" jshell> aaa.trim() $15 ==> "ãaaaã"
CharSequence
compare(CharSequence, CharSequence)
è¾æ¸é ã«æååãæ¯è¼ãã¾ã
åä½çã«ã¯Stringã®compareToãa.compareTo(b)ã¨æ¸ãã¦ããã®ãCharSequenceã«å¯¾å¿ãã¦staticã¡ã½ããã«ãªã£ãæãã§ãããã©ã¡ãããnullãªãã¬ãã½ã§ãã
Character
toString(int)
ãã¾ã¾ã§å¾®å¦ã«ä¸ä¾¿ã ã£ãã®ãã¡ãã£ã¨ä¾¿å©ã«ãªãã¾ããã
JDK10.0.1
jshell> Character.toString(65) | ã¨ã©ã¼: | ä¸é©åãªå: 精度ã失ãããå¯è½æ§ãããintããcharã¸ã®å¤æ | Character.toString(65) | ^^
JDK11ea14
jshell> Character.toString(65) $9 ==> "A"
Path
of(String, String...)
ãã¾ã¾ã§Paths.get()ã使ã£ã¦ããã¨ããããã»ãã®ä½æ³ã¨åæ§ã«of()ã§å¾ããããã«ãªãã¾ããã
Files
writeString(Path, CharSequence)
1ã¡ã½ããã§æååä¿åã§ããããã«ãªãã¾ããã
jshell> Files.writeString(Path.of("test.txt"), "Hello!!!") $3 ==> test.txt
readString(Path)
1ã¡ã½ããã§æååèªã¿è¾¼ã¿ã§ããããã«ãªãã¾ããã
jshell> Files.readString(Path.of("test.txt")) $4 ==> "Hello!!!"
Predicate
not(Predicate)
æ¡ä»¶ãå転ããå¿ è¦ãããããã«ã¡ã½ããåç §ã使ããªãã£ãã¨ããã§ãã¡ã½ããåç §ã使ããããã«ãªãã¾ãã
jshell> Stream.of("aa", "", "bb").filter(Predicate.not(String::isEmpty)).toArray() $23 ==> Object[2] { "aa", "bb" }
Collection
toArray(IntFunction)
ãã¾ã¾ã§åãã¡ããã¨ããããé åãListãªã©ããä½ãã®ã«list.toArray(new String[list.size())])ã¿ãããªãã£ããããè¨è¿°ãå¿ è¦ã ã£ãã®ããã¡ãã£ã¨ãã£ãããæ¸ããããã«ãªãã¾ããã
jshell> List.of("aa","bb").toArray(String[]::new) $1 ==> String[2] { "aa", "bb" }
Optional
isEmpty()
ãã¾ã¾ã§isPresent()ã¯ããã¾ããããisEmpty()ã追å ããã¾ããã
jshell> Optional.ofNullable(null).isEmpty() $5 ==> true
Pattern
asMatchPredicate()
asPredicateã¯findããPredicateã ã£ãã®ã§ãããmatchããPredicateãç¨æããã¾ããã
jshell> var pred = Pattern.compile("aaa").asPredicate() pred ==> java.util.regex.Pattern$$Lambda$25/0x00000008000b5040@2f686d1f jshell> pred.test("aaab") $7 ==> true jshell> var matPred = Pattern.compile("aaa").asMatchPredicate() matP ==> java.util.regex.Pattern$$Lambda$24/0x00000008000b6440@402a079c jshell> matPred.test("aaab") $9 ==> false
Thread
destroy() / stop(Throwable)
åé¤ããã¾ãããstop()ã¯æ®ã£ã¦ã¾ãã
ArrayIndexOutOfBoundsException
ã¡ãã»ã¼ã¸ã人é¡ã«åªãããªãã¾ããã
JDK10.0.1
jshell> new int[]{}[0] | java.lang.ArrayIndexOutOfBoundsException thrown: 0 | at (#8:1)
JDK11-ea14
jshell> new int[]{}[0] | Exception java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0 | at (#4:1)
IndexOutOfBoundsException
ããã¿ã«ãã¤ãã³ãå
¥ã£ã¦ãã®ãåãé¤ããã¾ããã
JDK10.0.1
jshell> List.of().get(0) | java.lang.IndexOutOfBoundsException thrown: Index 0 out-of-bounds for length 0 | at Preconditions.outOfBounds (Preconditions.java:64) | at Preconditions.outOfBoundsCheckIndex (Preconditions.java:70) | at Preconditions.checkIndex (Preconditions.java:248) | at Objects.checkIndex (Objects.java:372) | at ImmutableCollections$List0.get (ImmutableCollections.java:106) | at (#6:1)
JDK11-ea14
jshell> List.of().get(0) | Exception java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0 | at ImmutableCollections$ListN.get (ImmutableCollections.java:411) | at (#3:1)
å®ã¯List.of()ãList0ã¨ãList1ã¨ãè¦ç´ æ°ã«ããããå°ç¨ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ãè¿ãã¦ãã®ã§ããããããListNã«çµ±ä¸ããããã¨ããããã¾ãã
System
arraycopy
ã¨ã©ã¼ã¡ãã»ã¼ã¸ã人é¡ã«åªãããªãã¾ããã
JDK10
jshell> System.arraycopy(new int[0],0,new double[0],0,0) | java.lang.ArrayStoreException thrown
JDK11ea19
jshell> System.arraycopy(new int[0], 0, new double[0], 0, 0) | Exception java.lang.ArrayStoreException: arraycopy: type mismatch: can not copy int[] into double[]
setProperty(String, String)
ãã¾ã¾ã§java.homeã¨ãããããã¨ã¨ã©ããã¨ãªã£ã¦ãã¨æãã®ã§ãããã·ã¹ãã ã«å½±é¿ããªããªãã¾ããããã¶ãã
æ°å å·å¯¾å¿
ã¨ããããNEWERAã¨ãã¦å
¥ã£ã¦ã¾ãã
Javaの新元号対応を試す。そして実用には問題がある - きしだのはてな
Swing
ea20ãããã©ã³ãæç»ã§ã¦ãã³ã¼ãã®ããªã¨ã¼ã·ã§ã³ã»ã¬ã¯ã¿ãåæ ãããããããæªç¢ºèªã
Base64
ea20ããã¨ã³ã³ã¼ãã«AVX512ã使ãããã«ãªã£ãã®ã§éããªã£ãããããã
Windowsã§ã¯ç¢ºèªã§ãã¾ããã§ãããLinuxã ãããã
Boolean
parseBoolean
ç¡é§ãªnullãã§ãã¯ãçãã¦ã¡ãã£ã¨éããªã£ãããããã
JDK10
public static boolean parseBoolean(String s) { return ((s != null) && s.equalsIgnoreCase("true")); }
JDK11
public static boolean parseBoolean(String s) { return "true".equalsIgnoreCase(s); }
å·®ã«ã¤ãã¦ã¯æªç¢ºèª
List
copyOf
Java10ã§å°å
¥ãããcopyOfã§ãããsubListãã³ãã¼ããã¨ãã®æåããã¡ã ã£ãããããã·ãªã¢ã©ã¤ãºãã§ããªãã
ããã¾ã§ã¯å
±éã
jshell> var list1 = List.of("a","b","c") list1 ==> [a, b, c] jshell> var list2=list1.subList(1,2) list2 ==> [b] jshell> var list3=List.copyOf(list2) list3 ==> [b]
JDK11ea19
jshell> list2==list3 $13 ==> true jshell> new ObjectOutputStream(OutputStream.nullOutputStream()).writeObject(list3) | Exception java.io.NotSerializableException: java.util.ImmutableCollections$SubList | at ObjectOutputStream.writeObject0 (ObjectOutputStream.java:1185) | at ObjectOutputStream.writeObject (ObjectOutputStream.java:349) | at (#14:1)
JDK11ea20
jshell> list2==list3 $26 ==> false jshell> new ObjectOutputStream(OutputStream.nullOutputStream()).writeObject(list3) jshell>
TimSort
ãªãããã°ããã£ã¦ä¿®æ£ãããã½ã
https://blog.satotaichi.info/timsort-was-broken/