中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

JDK 11 已處于特性?xún)鼋Y(jié)狀態(tài),看看 Java 11 API 變更提案

2018-07-25    來(lái)源:oschina

容器云強(qiáng)勢(shì)上線(xiàn)!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
Java

自從上個(gè)月進(jìn)入“減速(ramp-down)”階段以來(lái),JDK 11 的特性已經(jīng)處于凍結(jié)狀態(tài)。這些重大的變化已被列為 JEP(JDK Enhancement Proposal 特性增強(qiáng)提議)。此外,JDK 11 中也有很多除 JEP 之外的變化,但官方尚未總結(jié)。因此,本文將列出我所知道的 JDK 11 中的 API 變更。

String

lines()

字符串實(shí)例方法,使用專(zhuān)門(mén)的 Spliterator 來(lái)懶惰地提供源字符串中的行

jshell> "test\nhoge\n".lines().map(String::toUpperCase).toArray()
$11 ==> Object[2] { "TEST", "HOGE" }

repeat(int)

按照參數(shù) int 提供的次數(shù)來(lái)重復(fù)字符串的運(yùn)行次數(shù)

jshell> "test".repeat(3)
$7 ==> "testtesttest"

isBlank()

驗(yàn)證當(dāng)前字符串是否為空,或者是否只包括空白字符(空白字符由 Character.isWhiteSpace(int) 驗(yàn)證)

jshell> var halfSpace = "\u0020"
halfSpace ==> " "

jshell> halfSpace.isBlank()
$11 ==> true

jshell> var fullSpace = "\u3000"
fullSpace ==> " "

jshell> fullSpace.isBlank()
$13 ==> true

strip()/stripLeading()/stripTrailing()

這三個(gè)方法的作用分別是去掉字符串頭和尾的空白符、字符串頭的空白符、字符串尾的空白符,基本與 trim()/trimLeft()/trimRight() 方法相同,不過(guò)它們的空白字符由 Character.isWhiteSpace(int) 驗(yàn)證

jshell> var aaa = fullSpace + "aaa" + fullSpace
aaa ==> " aaa "

jshell> aaa.strip()
$14 ==> "aaa"

jshell> aaa.trim()
$15 ==> " aaa "

CharSequence

compare(CharSequence, CharSequence)

按字典順序進(jìn)行排序

它被 CharSequence/StringBuffer/StringBuilder 中的 compareTo() 使用。因此,這三個(gè)類(lèi)都實(shí)現(xiàn)了 Comparable。

Character

toString(int)

JDK 11 使這個(gè)過(guò)程變得更加方便

JDK10.0.1

jshell> Character.toString(65)
|  Error:
|  incompatible types: possible lossy conversion from int to char
|  Character.toString(65)
|

JDK11ea14

jshell> Character.toString(65)
$9 ==> "A"

Path

of(String, String...)

此前我們需要使用 Paths.get()。現(xiàn)在,我們像其他類(lèi)一樣使用 of()。

Files

writeString(Path, CharSequence)

我們可以使用該方法來(lái)保存一個(gè) String 字符串。

jshell> Files.writeString(Path.of("test.txt"), "Hello!!!")
$3 ==> test.txt

readString(Path)

我們可以使用該方法來(lái)讀取一個(gè) String 字符串。

jshell> Files.readString(Path.of("test.txt"))
$4 ==> "Hello!!!"

Reader

nullReader()

使用該方法,我們可以得到一個(gè)不執(zhí)行任何操作的 Reader。

Writer

nullWriter()

使用該方法,我們可以得到一個(gè)不執(zhí)行任何操作的 Writer。

InputStream

nullInputStream()

使用該方法,我們可以得到一個(gè)不執(zhí)行任何操作的 InputStream。

OutputStream

nullOutputStream()

使用該方法,我們可以得到一個(gè)不執(zhí)行任何操作的 OutputStream。

Predicate

not(Predicate)

此前在需要反轉(zhuǎn)條件的地方,我們選擇不使用方法引用,F(xiàn)在相反,我們可以使用方法引用。

jshell> Stream.of("aa", "", "bb").filter(Predicate.not(String::isEmpty)).toArray()
$23 ==> Object[2] { "aa", "bb" }

Collection

toArray(IntFunction)

此前,我們需要使用像 list.toArray(new String[list.size())]) 這樣的無(wú)風(fēng)格標(biāo)記(non-stylish notation)來(lái)從一個(gè)集合創(chuàng)建一個(gè)類(lèi)型化數(shù)組。現(xiàn)在,我們可以以風(fēng)格標(biāo)記(stylish notation)的方式進(jìn)行編寫(xiě)。

jshell> List.of("aa","bb").toArray(String[]::new)
$1 ==> String[2] { "aa", "bb" }

Optional/OptionalInt/OptionalLong/OptionalDouble

isEmpty()

isPresent() 方法此前已經(jīng)存在,現(xiàn)在我們使用 isEmpty() 方法。

jshell> Optional.ofNullable(null).isEmpty()
$5 ==> true

TimeUnit

convert(Duration)

該方法已經(jīng)添加到 java.util.concurrent.TimeUnit 中。

Pattern

asMatchPredicate()

到目前為止,只有 asPredicate() 方法,但現(xiàn)在我們還擁有 asMatchPredicate() 方法。

jshell> var pred = Pattern.compile("aaa").asPredicate()
pred ==> java.util.regex.Pattern$Lambda$25/0x00000008000b5040@2f686d1f

jshell> pred.test("aaa")
$6 ==> true

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("aaa")
$9 ==> true

jshell> matPred.test("aaab")
$10 ==> false

ListSelectionModel

已添加 getSelectedIndices() / getSelectedCount() 方法

Thread

destroy()/stop(Throwable)

移除 destroy() 方法,保留 stop() 方法。

Policy

已移除 javax.security.auth.Policy。

ArrayIndexOutOfBoundsException

拋出的異常信息已修改:

JDK10.0.1

jshell> new int[]{}[0]
|  java.lang.ArrayIndexOutOfBoundsException thrown: 0
|        at (#8:1)

JDK11ea14

jshell> new int[]{}[0]
|  Exception java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
|        at (#4:1)

IndexOutOfBoundsException

在本次變更中,已在異常信息中移除 hyphens。

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)

JDK11ea14

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)

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 會(huì)導(dǎo)致一些問(wèn)題,現(xiàn)在問(wèn)題已得到解決。

支持 Japanese New Era

Japanese Imperial Era 計(jì)劃于 2019.5.1 改用新的規(guī)則。

本次變更是作為 NewEra 占位符引入的。

在日本政府宣布之后,它將在 JDK 12.0.1 中進(jìn)行更新。

JDK10.0.1

jshell> JapaneseDate.of(2019, 5, 1)
$15 ==> Japanese Heisei 31-05-01

JDK11 ea18

jshell> JapaneseDate.of(2019, 5, 1)
$3 ==> Japanese NewEra 1-05-01

目前我們還未能將 May 1st Heisei 31 作為我們的 JapaneseDate。

JDK10.0.1

jshell> JapaneseDate.of(JapaneseEra.HEISEI, 31, 5, 1)
$14 ==> Japanese Heisei 31-05-01

JDK11 ea18

jshell> JapaneseDate.of(JapaneseEra.HEISEI, 31, 5, 1)
|  Exception java.time.DateTimeException: year, month, and day not valid for Era
|        at JapaneseDate.of (JapaneseDate.java:231)
|        at (#2:1)

Base64

從 ea20 起,使用 AVX512 進(jìn)行編碼會(huì)變得更快,但在 Windows 上無(wú)法確定。

Boolean

parseBoolean

官方表示,在刪除冗余的空檢查后,它的速度變得更快。

JDK10

public static boolean parseBoolean(String s) {
        return ((s != null) && s.equalsIgnoreCase("true"));
    }

JDK11

public static boolean parseBoolean(String s) {
    return "true".equalsIgnoreCase(s);
}

還未確定是否存在性能差異。

TimSort

TimSort 是用于 Array.sort() 和 Collection.sort() 的主要算法。

但它有一個(gè)錯(cuò)誤,主要發(fā)生在為某些序列拋出一個(gè) ArrayIndexOutOfBoundsException 異常,不過(guò)似乎已修復(fù),尚未確定。

來(lái)源:https://dzone.com/ 編譯:開(kāi)源中國(guó)

標(biāo)簽: isp

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀(guān)點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:OTP 20.3.8.3 發(fā)布,Erlang 編寫(xiě)的應(yīng)用服務(wù)器

下一篇:騰訊開(kāi)源大規(guī)模 Node.js 微服務(wù)框架 Tars.js