我正在搜索在控制台上打印 System.out.println() 参数值的 java 源代码。我检查了 PrintStream
、FilterOutputStream
和 OutputStream
类,它们都没有完整的方法实现,也没有任何对 native 代码的引用。
System.out.println
值如何打印在控制台上,哪个 native 方法正在执行实际工作?
最佳答案
您必须深入了解装饰器模式包装器。在底部你会发现FileOutputStream
,特别是这个方法:
private native void writeBytes(byte b[], int off, int len) throws IOException;
使用此代码来玩它:
public static void main(String[] args) throws Exception {
nav(nav(System.out));
}
static Object nav(Object o) throws Exception {
final Field[] fs = o.getClass().getSuperclass().getDeclaredFields();
for (Field f : fs) {
f.setAccessible(true);
final Object r = f.get(o);
System.out.println(r);
return r;
}
return null;
}
关于java - System.out.println ('teststring' ) 如何在控制台上打印该值?哪个 native 方法正在执行实际工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10378921/