开发者

How does setOut method change the value of System.out which is final in System class [duplicate]

开发者 https://www.devze.com 2023-03-16 08:14 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: java: “final” System.out?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

java: “final” System.out?

Can someone please help me in understanding how the setOut method works?

It can change the current pipe lining of 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消