抽象类InputStream为什么可以生成实例java.lang.System.in?

CodeRed 2003-12-04 09:10:25
在j2sdk-1_4_2-doc中java.io.InputStream被定义为
public abstract class InputStream extends Object
既然是 abstract 类 为什么在java.lang.System中可以生成in这个实例?
谢谢各位了。
...全文
69 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
flowercat 2003-12-04
  • 打赏
  • 举报
回复
其实看下源代码什么都清楚了
flowercat 2003-12-04
  • 打赏
  • 举报
回复
/**
* Initialize the system class. Called after thread initialization.
*/
private static void initializeSystemClass() {
props = new Properties();
initProperties(props);
sun.misc.Version.init();
FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
setIn0(new BufferedInputStream(fdIn));
setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));
setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true));

// Enough of the world is now in place that we can risk
// initializing the logging configuration.
try {
java.util.logging.LogManager.getLogManager().readConfiguration();
} catch (Exception ex) {
// System.err.println("Can't read logging configuration:");
// ex.printStackTrace();
}

// Load the zip library now in order to keep java.util.zip.ZipFile
// from trying to use itself to load this library later.
loadLibrary("zip");

// Subsystems that are invoked during initialization can invoke
// sun.misc.VM.isBooted() in order to avoid doing things that should
// wait until the application class loader has been set up.
sun.misc.VM.booted();
}
flowercat 2003-12-04
  • 打赏
  • 举报
回复
/**
* The following two methods exist because in, out, and err must be
* initialized to null. The compiler, however, cannot be permitted to
* inline access to them, since they are later set to more sensible values
* by initializeSystemClass().
*/
private static InputStream nullInputStream() throws NullPointerException {
if (currentTimeMillis() > 0)
return null;
throw new NullPointerException();
}

private static PrintStream nullPrintStream() throws NullPointerException {
if (currentTimeMillis() > 0)
return null;
throw new NullPointerException();
}
Yanbin_Q 2003-12-04
  • 打赏
  • 举报
回复
正确理解
多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态多态
flowercat 2003-12-04
  • 打赏
  • 举报
回复
/**
* The "standard" input stream. This stream is already
* open and ready to supply input data. Typically this stream
* corresponds to keyboard input or another input source specified by
* the host environment or user.
*/
public final static InputStream in = nullInputStream();

源代码如上
flowercat 2003-12-04
  • 打赏
  • 举报
回复
看文档

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧