A / B計畫
• JDK 7 Features updated ! Plan B has
apparently been approved
– http://www.baptiste-wicht.com/2010/09/jdk-7-
features-updated-plan-b-is-apparently-here/
8.
JDK7 ...
λ Jigsaw
Language support for collections
Annotations on Java types
Small language enhancements
•Strings in switch
• Binary integral literals and underscores in
numeric literals
• Multi-catch and more precise rethrow
• Improved Type Inference for Generic
Instance Creation (diamond)
• try-with-resources statement
• Simplified Varargs Method Invocation
Multi-catch
• It isa compile-time error if a disjunctive
type contains two alternatives Di, Dj where
Di is a subtype of Dj.
18.
Multi-catch
• An exceptionparameter whose type is a
disjunctive type is implicitly considered to
be final.
try { /* throws some ReflectiveOperationException */ }
catch (final ClassNotFoundException ex1) { /* body */ }
catch (final IllegalAccessException ex2) { /* body */ }
Simplified Varargs Method
Invocation
• JDK7...
提醒設計 doSome() 保證不會發生 Heap Pollution
....: warning: [unchecked] Possible heap pollution from parameterized var
arg type T
public static <T> List<T> doSome(T... t) {
^
where T is a type-variable:
T extends Object declared in method <T>doSome(T...)
1 warning
NIO2
NIO
• File System API
• Channels API
– Updates to socket channel API
– Asynchronous I/O
• java.nio
– Buffer
– Channel
– Selector
– Charset
49.
File System API
•java.io.File 怎麼了?
– Not initially written to be extended
– Many of the methods without exceptions
– Methods behaved inconsistently across volumes and
file systems
– Methods for gaining simultaneous metadata about
files were inefficient
– Developers also requested the ability to develop their
own file system implementations, for examples, zip
files
– ...
50.
File System API
•新套件
– java.nio.file
– java.nio.file.attribute
• Java Tutorials: File I/O (Featuring NIO.2)
– http://download.oracle.com/javase/tutorial/essential/io
/fileio.html
51.
關於 Path
• Methods to access components
• Methods to test and compare
• Methods to combine paths
• File operations
• All methods that access file system throw
IOException
• No other checked exceptions in API