为什么” system.out.println()中的静态字段,即使将其分配为NULL作为声明中的最终值,也不会引发null异常吗?

发布于 2025-01-26 03:12:21 字数 701 浏览 1 评论 0原文

我对“系统”类中的“ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山有枢 2025-02-02 03:12:21

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文