在Java 7中新的Try-with-Resources語法中,我是否需要擔心資源的順序?在Java 7中試用資源?
try (InputStream in = loadInput(...); // <--- can these be in any order?
OutputStream out = createOutput(...)){
copy(in, out);
}
catch (Exception e) {
// Problem reading and writing streams.
// Or problem opening one of them.
// If compound error closing streams occurs, it will be recorded on this exception
// as a "suppressedException".
}
如果資源依賴於*彼此*,則(好吧,「可能」取決於他們如何做)。否則......不。 – 2011-07-13 03:10:18