Is there any difference in these statements
System.out.println(error);
AND
PrintStream ps = new PrintStream((OutputStream)S
System.out
is already a PrintStream
,
PrintStream ps = new PrintStream((OutputStream)(System.out));
would only wrap it once more which seems pointless.
Basically, there is no difference. The second way is too prolonged. out is a static field of type java.io.PrintStream in System class. You could directly use it instead of casting it to Outputstream and again wrapping it inside another PrintStream reference. They both are going to use the same underlying PrintStream object regardless.
There is no difference except for the fact that you made a copy of out
.
From JavaDoc
out
public static final PrintStream out
It is already of type PrintStream
.