小编Chr*_*urt的帖子

为什么Double.NaN在包装在Double实例中时自相同?

这个问题我学到了Double.NaN不等于它自己.

我正在为自己验证这一点,并注意到如果你在Double实例中包装Double.NaN则不是这种情况.例如:

public class DoubleNaNTest {
    public static void main(String[] args) {
        double primitive = Double.NaN;
        Double object = new Double(primitive);

        // test 1 - is the primitive is equal to itself?
        boolean test1 = primitive == primitive;

        // test 2 - is the object equal to itself?
        boolean test2 = object.equals(object);

        // test 3 - is the double value of the object equal to itself?
        boolean test3 = object.doubleValue() == object.doubleValue();

        System.out.println("Test 1 = " + test1); …
Run Code Online (Sandbox Code Playgroud)

java

11
推荐指数
2
解决办法
2160
查看次数

标签 统计

java ×1