之前的代码是这样的 -
try {
some other code
......
......
ByteArrayInputStream annoBais = new ByteArrayInputStream(annoBytes);
DataInputStream dis = new DataInputStream(annoBais);
InputStream annoStream = dis;
inputRecord.put("XMLStream", annoStream);
MappedRecord resultMappedRecord = (MappedRecord)interaction.execute(interactionSpec,inputRecord);
HashMap mappedAnnotIds = (HashMap)resultMappedRecord.get(("ResultHashMap").toString());
annoStream.close(); //closed here
annoBais.close(); // closed here
dis.close(); // closed here
......
......
some more code
}
我把它改成了——
try {
some other code
......
......
@lombok.Cleanup ByteArrayInputStream annoBais = new ByteArrayInputStream(annoBytes);
@lombok.Cleanup DataInputStream dis = new DataInputStream(annoBais);
@lombok.Cleanup InputStream annoStream = dis;
inputRecord.put("XMLStream", annoStream);
MappedRecord resultMappedRecord (MappedRecord)interaction.execute(interactionSpec,inputRecord);
HashMap mappedAnnotIds = (HashMap)resultMappedRecord.get(("ResultHashMap").toString());
......
......
some more code
}
@lombok.Cleanup 是否具有相同的范围?它会在之前手动关闭的地方关闭吗?如果没有,我怎样才能以它仍然具有相同范围的方式关闭它?