gpt4 book ai didi

java - 静态成员的方法是否被视为静态?

转载 作者:行者123 更新时间:2023-12-01 19:49:58 25 4
gpt4 key购买 nike

在以下来自 pg.1 的静态导入示例中。 《Oracle OCA/OCP Java SE 7 程序员 I 和 II 学习指南》第 16 条:

import static java.lang.System.out;              // 1
import static java.lang.Integer.*; // 2
public class TestStaticImport {
public static void main(String[] args) {
out.println(MAX_VALUE); // 3
out.println(toHexString(42)); // 4
}
}

书中提到标记为 3 的行:

“现在我们终于看到了静态导入功能的好处!我们不必在 System.out.println 中键入 System!哇!其次,我们不必在 Integer 中键入 Integer。 MAX_VALUE。因此,在这行代码中,我们能够使用静态方法和常量的快捷方式。

这里将 println 引用为静态方法是否有错误?

上面的程序如文中所示给出。

对于标记为 4 的行,书上说:“最后,我们再做一个快捷方式,这次是针对 Integer 类中的方法。”

最佳答案

引自书中:

  1. Now we’re finally seeing the benefit of the static import feature! We didn’t have to type the System in System.out.println! Wow! Second, we didn’t have to type the Integer in Integer.MAX_VALUE. So in this line of code we were able to use a shortcut for a static method AND a constant.

你的批评是有道理的。在那行代码中,我们没有使用静态方法的快捷方式。它只是静态字段的快捷方式。

关于java - 静态成员的方法是否被视为静态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51759353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com