找回密码
 立即注册
MATHstatic静态class | 软件设计/软件工程 2022-05-02 227 0star收藏 版权: . 保留作者信息 . 禁止商业使用 . 禁止修改作品
具有静态方法的类通常(尽管不一定)不打算被初始化。

私有构造函数可用于限制非抽象类被初始化。
比如java中的数学类。 它使构造函数标记为私有,因此您无法创建 Math 的实例。 但是 Math 类不是静态类。

这是数学课:

public final class Math {


    /**
     * Don't let anyone instantiate this class.
     */
    private Math() {}


    public static final double E = 2.7182818284590452354;
//……
    public static double sin(double a) {
        return StrictMath.sin(a); // default impl. delegates to StrictMath
    }
//……
}

使用静态方法调用类中的静态方法时,直接使用类名.方法名即可。

例如,math.sin();

(Classes with static methods are usually (though not necessarily) not intended to be initialized.
Private constructors can be used to restrict non abstract classes from being initialized.
For example, math classes in Java. It marks the constructor private, so you cannot create an instance of math. But the math class is not static.
This is math:
public final class Math {
/**
* Don't let anyone instantiate this class.
*/
private Math() {}
public static final double E = 2.7182818284590452354;
//……
public static double sin(double a) {
return StrictMath. sin(a); //  default impl.  delegates to StrictMath
}
//……
}
When using static methods to call static methods in a class, the class name is used directly Method name is enough.
For example, math sin();
)





上一篇:GC分析中提到的根对象是什么
下一篇:无效的线程间操作 PROGRESSBAR2 无法访问线程