I have some code like this:
class Foo { public double x; } void test() { Foo foo = new Foo(); // Is this a valid way to test for zero? \'x\' ha
In Java, 0 is the same as 0.0, and doubles default to 0 (though many advise always setting them explicitly for improved readability). I have checked and foo.x == 0 and foo.x == 0.0 are both true if foo.x is zero
foo.x == 0
foo.x == 0.0
foo.x