在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