0

Since out variable of System class present in package java.lang; is initialized to null, still why it does not throw null pointer exception.

public final static PrintStream out = null;

Good Vibes
  • 163
  • 2
  • 12
  • 5
    or just read the first comment inside the class: "VM will invoke the initializeSystemClass method to complete the initialization for this class separated from clinit" (which is a `native` call) `System` is very special, `out` can also be changed by calling `setOut` despite being `final` – user85421 Sep 15 '19 at 06:52
  • 1
    @GhostCat That won't work _in this specific case_; the JLS itself makes an exception for the definition of `final` for the system streams, and that's _not_ visible until you get into the C++ of the source code. – chrylis -cautiouslyoptimistic- Sep 15 '19 at 07:18
  • @chrylis Yeah,I didnt have my coffee yet. And worse: I knew there is a DUP for this one, but wasn't able to find it. – GhostCat Sep 15 '19 at 07:45

0 Answers0