Java 7
基礎語法
Diamond Operator
泛型判斷改進
String in Switch Statement
Switch 加入 String 判斷
Number Formatting
數字型態加強。
Underscores in numeric literals,提供了數字下劃線。
Binary Integer Literals,二進制形式表示文字。
Try - Catch with Resource
自動資源管理。
Suppressed Exceptions
被抑制的例外。
若一個例外被 catch 之後在catch 或 finally 階段又發生了例外,通常會拋出第一個錯誤,第二個則會被抑制。
Multi Catch
多個錯誤捕捉。
Library
NIO 2.0
引入了四個非同步Channel, 用於支援非同步讀寫。
同時, 還增加了對檔案系統和檔案屬性的支援, 提供了WatchService / FileVisitor 這些高階功能。
Method Handles
java.lang.invoke.MethodHandles,是一種用於查找,修改和調用方法的低級機制。
A method handle is a typed, directly executable reference to an underlying method, constructor, field, or similar low-level operation, with optional transformations of arguments or return values.
Fork / Join Framework
Fork/Join框架是一個實現了ExecutorService 介面的多線程處理器。
JVM
INVOKEDYNAMIC
自Java 1.0以來的第一個新字節碼。
其目的用戶代碼使用方法處理API來確定運行時的調度,而不會遭受性能損失和與反射相關的安全問題。
The intent is that user code determines dispatch at runtime using the method handles API whilst not suffering the performance penalties and security problems associated with reflection. In fact, the stated aim of invokedynamic is to be as fast as regular method dispatch (invokevirtual) once the feature has matured sufficiently.
但是無論提交的Java代碼如何,javac都不會產生包含invokedynamic的字節碼。
在 Java 8中有所改變,在Java 8中,現在已經生成了invokedynamic,並在後台使用它來實現lambda表達式和默認方法以及Nashorn的主要調度機制。
The astute reader will have noticed that all calls to Java methods are compiled to one of these four opcodes so the question arises - what is invokedynamic for, and why is it useful to Java developers?
The features main goal was to create a bytecode to handle a new type of method dispatch - that essentially allows application-level code to determine which method a call will execute, and to do so only when the call is about to execute. This allows language and framework writers to support much more dynamic programming styles than the Java platform previously provided.
核心概念是 java.lang.invoke.MethodHandles ,也透過 Java 獨立使用。
參考資料
Last updated
Was this helpful?