News for hackers. Stuff that matters.
Re:Java for Everything by x0x0 on Sunday November 30, 2014 @06:41PM (#8678701)
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);
Re:Java for Everything by adiM on Sunday November 30, 2014 @06:49PM (#8678733)
Why not:

    return o2.compareTo(o1);
Re:Java for Everything by x0x0 on Sunday November 30, 2014 @07:58PM (#8678969)
because the o2 vs o1 is easy to miss, while the -1 makes it obvious i'm intentionally reversing. my .02
Re:Java for Everything by fyolnish on Sunday November 30, 2014 @08:49PM (#8679105)
Not if you give them more descriptive names
Re:Java for Everything by cdman on Monday December 01, 2014 @02:46AM (#8679917)
No, you can't. In particular -1 * Integer.MIN_VALUE == Integer.MIN_VALUE.
Re:Java for Everything by organsnyder on Friday December 05, 2014 @03:36PM (#8706745)
That 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.