3 ms·
I think the point is that he needed a comparison function not and equals function. thus the subtraction. Erric Lippert had a nice series on subtle bugs in co
by lukesandberg 15y ago
I think the point is that he needed a comparison function not and equals function. thus the subtraction. Erric Lippert had a nice series on subtle bugs in compareTo implementations, in part3 he talks about a similar version of this bug. http://blogs.msdn.com/b/ericlippert/archive/2011/01/27/spot-the-defect-bad-comparisons-part-three.aspx http://blogs.msdn.com/b/ericlippert/archive/2011/01/27/spot-...
tldr; if you aren't doing a comparison in your compareTo implementation, you probably have a bug.
- viraptor 15y agoI thought it might too, but then he writes: "A zero result means equals, and non-zero means not-equals… and then the results are cast to 32 bits." So he didn't care about ordering.