我刚才有一个我无法回答的问题.
假设您在Java中使用此循环定义:
while (i == i) ;
Run Code Online (Sandbox Code Playgroud)
如果循环不是无限循环并且程序只使用一个线程i,i那么类型和值是什么?
谁可以给我解释一下这个?在C#中,double.NaN不等于double.NaN
bool huh = double.NaN == double.NaN; // huh = false
bool huh2 = double.NaN >= 0; // huh2 = false
bool huh3 = double.NaN <= 0; // huh3 = false
Run Code Online (Sandbox Code Playgroud)
我可以将什么常数与double.NaN相比并得到真实?
从这个问题我学到了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) toString()方法,==运算符和equals()方法如何在引用和基元类型上以不同或相似的方式工作?