小编Asg*_*ard的帖子

什么都不做的 PrintStream

我试图使PrintStream每次调用其方法时什么都不做。该代码显然没有错误,但是当我尝试使用它时,我得到了一个java.lang.NullPointerException: Null output stream. 我究竟做错了什么?

public class DoNothingPrintStream extends PrintStream {
    
    public static final DoNothingPrintStream doNothingPrintStream = new DoNothingPrintStream();

    private static final OutputStream support = new OutputStream() {
        public void write(int b) {}
    };
    // ======================================================
        // TODO | Constructor
    
    /** Creates a new {@link DoNothingPrintStream}.
     * 
     */
    private DoNothingPrintStream() {
        super( support );
        if( support == null )
            System.out.println("DoNothingStream has null support");
    }
    
    
}
Run Code Online (Sandbox Code Playgroud)

java nullpointerexception printstream

0
推荐指数
1
解决办法
74
查看次数

标签 统计

java ×1

nullpointerexception ×1

printstream ×1