Quando ho letto il codice sorgente da java.io.BufferedInputStream.getInIfOpen(), sono confuso sul motivo per cui ha scritto codice come questo:
/**
* 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;
}
Perché utilizza l'alias invece di utilizzare indirettamente la variabile di campo come di seguito:
/**
* 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;
}
Qualcuno può dare una spiegazione ragionevole?
ifdichiarazione?
Eclipse, non puoi mettere in pausa un debugger suifun'istruzione. Potrebbe essere una ragione per quella variabile alias. Volevo solo buttarlo là fuori. Io speculo, ovviamente.