为什么” system.out.println()中的静态字段,即使将其分配为NULL作为声明中的最终值,也不会引发null异常吗?
我对“系统”类中的“ of”静态字段感到困惑,而不是抛出任何nullpointer异常,即使将其分配为“ null”作为声明中的最终值。
该语句为 - “ system.out.println();” - 为了理解整个语句的实现,我通过在语句上按CTRL并单击“打开声明”选项来追溯到其实现。
这是在“系统”类中声明“输出”静态字段的方式。
public static final PrintStream out = null;
要检查这种实现,我尝试了一个非常基本的代码,而IDE确实抛出了NullPoInterException。
我尝试过的代码下面是下面
public class examplo1 {
public static final TryingAnother sameTry = null;
public static void main(String[] args) {
sameTry.addO();
System.out.println();
}}
尝试的类代码,
public class TryingAnother {
int a = 25;
public void addO()
{
a = a + 25;
System.out.println(a);
}}
感谢您的答案!
I'm confused with the 'out' static field inside 'System' class, not throwing any nullpointer exception, even though it is assigned 'null' as final value in its declaration.
The statement is - "System.out.println();" - to understand this entire statement's implementation, I traced back to its implementation, using Eclipse IDE by pressing ctrl on the statement and clicking 'Open Declaration' option.
This how the 'out' static field is declared inside 'System' class.
public static final PrintStream out = null;
To check with this kind of implementation, I tried a very basic code, and the IDE did throw a NullPointerException.
The code I have tried is below
public class examplo1 {
public static final TryingAnother sameTry = null;
public static void main(String[] args) {
sameTry.addO();
System.out.println();
}}
TryingAnother class code below
public class TryingAnother {
int a = 25;
public void addO()
{
a = a + 25;
System.out.println(a);
}}
Thanks in advance for the answers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
system.out是通常是终端的默认输出流。如果按照您的编写声明,则INIT由JVM完成
System.out is the default outputstream which is normally the terminal. If it is declared as you have written, then the init is done by the JVM