Por que BufferedInputStream copia um campo para uma variável local em vez de usar o campo diretamente
Quando leio o código fonte dejava.io.BufferedInputStream.getInIfOpen()
, Estou confuso sobre por que ele escreveu código como este:
/**
* Check to make sure that underlying input stream has not been
* nulled out due to close; if not return it;
*/
private InputStream getInIfOpen() throws IOException {
InputStream input = in;
if (input == null)
throw new IOException("Stream closed");
return input;
}
Por que ele está usando o alias em vez de usar a variável de campoin
diretamente como abaixo:
/**
* Check to make sure that underlying input stream has not been
* nulled out due to close; if not return it;
*/
private InputStream getInIfOpen() throws IOException {
if (in == null)
throw new IOException("Stream closed");
return in;
}
Alguém pode dar uma explicação razoável?