Trong cú pháp Try-with-Resources mới trong Java 7, tôi có cần phải lo lắng về thứ tự các tài nguyên không?Thử-với-tài nguyên trong 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".
}
Nếu tài nguyên phụ thuộc * mỗi khác *, có (tốt, "có thể" tùy thuộc vào về cách họ làm). Nếu không ... không. –