How does setOut method change the value of System.out which is final in System class [duplicate]
Possible Duplicate:
java: “final” System.out?
Can someone please help me in understanding how the setOut
method works?
System.out开发者_运维知识库
from Monitor to PrintStream object, but how is it changing reference of out?System#setOut
internally calls a native method to redirect out
. In other words: voodoo magic ;)
Since Java is open source, let's have a look:
http://www.mavenjava.com/sun/jdk/1.6.0/src/java/lang/System.java.html#System.setOut%28java.io.PrintStream%29
It calls out to a native method to set the output - the JVM basically bypasses the "final" check.
精彩评论