您的版本未明确定义应关闭的内容,例如
CloseableResource thing;Parameter a;try (a = (thing = methodThatCreatesAThingAndDoesSomeSideEffect()).getParameter()) {
还要写的话怎么办
try (12) {
或者其他的东西?
也
CloseableResource thing1 = methodThatCreatesAThingAndDoesSomeSideEffect();CloseableResource thing2 = methodThatCreatesAThingAndDoesSomeSideEffect();try(thing1) {}
为什么只关闭
thing1?
ALSO2
CloseableResource Thing1 = methodThatCreatesAThingAndDoesSomeSideEffect();
try(thing1) {}thing1.doSomethingonClosedResource();
由于
thing1仍然存在。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)