Effective compareTo() for primitive long
问题 Working on a sorted list I came to a point I needed to implement a compareTo() function for primitive long values. I'm not looking for the obvious naive implementation , but was wondering if there's an elegant one-liner code to do that (without creating a new Long(value)). Maybe something like this: @Override public int compareTo(MyClass that) { return (int) ((value - that.value) >>> 32); } Can anyone verify that would work and/or suggest another implementation? 回答1: One liner code to that: