News for hackers. Stuff that matters.
Re:Java for Everything by twic on Sunday November 30, 2014 @06:23PM (#8678645)
I'll meet you halfway:

      ints.sort((o1, o2) -> {
          if (o1.equals(o2)) {
            return 0;
          } else if (o1 < o2) {
            return 1; 
          } else { 
            return -1;
          }
      });
Or may i suggest a version with a guard clause and a simple ternary:

      ints.sort((o1, o2) -> {
          if (o1.equals(o2)) return 0;
          return (o1 < o2) ? 1 : -1;
      });
There's definitely no need for the 'new Comparator' boilerplate any more. That's not the kind of verbosity that adds clarity; it's just ceremony.

There are no comments on this comment yet.