4

I looked at java.lang.System source code and found the following lines:

public final static InputStream in = null;
public final static PrintStream out = null;
public final static PrintStream err = null;

I know that a final reference can't be reassigned, and therefore methods calls such as "System.out.println" should cause a NullPointerException. On the other hand, I saw that System.setOut is implemented in C (well, setOut0), and wondered what magic is happening here, and how I could reassign a value to a final reference.

Brrch
  • 331
  • 1
  • 4
  • 1
    The `final` modifier really only applies to the Java level. They are probably set from native code at a very early point in time. I'd guess the assignment's only purpose is to shut up the compiler about a final variable never being assigned. – Wormbo May 05 '15 at 19:10

0 Answers0