47

Is there an easy way to sort methods within a class in Eclipse?

3
  • 1
    Why would you want to sort the methods? May 12, 2009 at 18:47
  • 4
    I've got a couple of versions of the class to merge; this will make merging more straightforward, because some methods wound up at different places and diff doesn't resolve them nicely. May 12, 2009 at 18:49
  • By name is sufficient, but by protection, static-ness, and name is probably better. May 12, 2009 at 18:50

2 Answers 2

68

select the class, Source > Sort Members

you can set the order in Java preferences

via Eclipe forums

2
  • 1
    Sometimes this gives compilation error.Say if one variable is instantiated based on the other and it on sort the variable goes above. I was wondering if this can be handled in any way
    – Ravisha
    Jun 23, 2010 at 5:01
  • @Ravisha I usually handle this by hacking the variable name to force alphabetic order OR simply by not using sort members on that file... Mar 11, 2013 at 12:17
17

Found it on the Eclipse newsgroup:

select the class, Source > Sort Members

3
  • 1
    This answer was actually added one minute earlier than the selected one.
    – Cacovsky
    Aug 5, 2014 at 2:46
  • 2
    First isn't always best, and generally it's better to have an answer from someone other than the OP. The accepted answer also includes some useful information about settings which my answer here is missing. Aug 5, 2014 at 14:03
  • 1
    Oh, I didn't noticed you were the OP. I understand now your decision.
    – Cacovsky
    Aug 5, 2014 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.