I was curious, I see a lot of things:
Arrays.sort(array, new Comparator<Integer>() {
public int compare(Integer a, Integer b) {
return Math.abs(a) < Math.abs(b);
}
});
since the anonymous class created here does not have instance variables, is the standard JDK compiler smart enough to only have one instance of this anonymous class and reuse it? Or is it desirable to instantiate this anonymous class in a static field and always pass a static Comparator object?
The UPDATE . When I say "JDK compiler", I also mean the JIT part. The above is also just an example. I was very interested if, as a best practice, I would create static fields for the above, instead of embedding anonymous class instances. In some cases, the issue of using performance / resource will be minor. But other cases may not be ...
source
share