Коли я читаю вихідний код із java.io.BufferedInputStream.getInIfOpen(), я плутаюсь, чому він написав такий код:
/**
* 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;
}
Чому він використовується псевдонімом замість inпрямої змінної поля, як нижче:
/**
* 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;
}
Чи може хтось дати розумне пояснення?
ifзаяву?
Eclipseне можна призупинити налагоджувач уifзаяві. Можливо, це буде причиною цієї змінної псевдоніму. Просто хотів це викинути. Думаю, звичайно.