4 ms·
one line is way more readable than 7 lines taking up valuable vertical and brain space it could also be accomplished with return -1 * o1.compareTo(o2);
by x0x0 12y ago
one line is way more readable than 7 lines taking up valuable vertical and brain space
it could also be accomplished with
return -1 * o1.compareTo(o2);
- adiM 12y agoWhy not: return o2.compareTo(o1);
- cdman 12y agoNo, you can't. In particular -1 * Integer.MIN_VALUE == Integer.MIN_VALUE.
- organsnyder 12y agoThat would probably never matter in practice, though—I've rarely seen compareTo() return anything other than -1, 0, or 1; certainly never anything approaching MAX/MIN_VALUE. Still, bravo for considering all of the edge cases.