You are refering to this comment I believe:
"The comparator definition should be before the add code – Bryan Glazer"
There is no technical reason to put the intComp
declaration before (or after) the main
declaration. It works fine either way.
The only possible reason for putting the comparator earlier is stylistic. That is, the intComp
declaration is a static variable, and it is conventional to declare variables at the start of a class.
I'm inclined agree with the style point, but it is a minor issue. Also, if it was me, I'd declare the comparator as final
, give it a more meaningful name, and use the "constant" naming style; e.g. INT_COMP
(but more meaningful).
Re Nambari's comment:
"I think it is bad practice, anonymous class are for limited scope not for global scope."
This is nonsense. It is quite common for anonymous classes to be used in this way. Sure, anonymous classes can also be used in nested scopes ... and that is one of their advantages ... but that in no way means that this pattern is wrong.