根据AutoCloseable接口的定义,我
必须调用所有实例。
即我必须这样写。 close()
try(A a = new A()){
//do something
}
在java.sound.sampled.SourceDataLine接口中,
或更常见的是,在java.sound.sampled.Line接口中,
是否需要调用所有实例,
或者我必须仅在调用后close()调用? close() open()
如果官方文档明确说明我必须close只当isOpened,
我想这样写。但我找不到提及。
//can I write like this ?
SourceDataLine sdl;
try{
sdl = AudioSystem.getSourceDataLine(audioFormat);
sdl.open(audioFormat,bufferSize);
}catch(LineUnavailableException ex){
throw new RuntimeException(null,ex);
}
try(SourceDataLine sdlInTryWithResources = sdl){
//do something
}