4

I've noticed that when I inline implement an interface in the class body itself, ie. not inside a method,

Runnable r = new Runnable() {    

    @Override
    public void run() {
        // do something
    }
};

and then press CTRL + SHIFT + F (automatically fixes indentation), eclipse indents the methods alot like:

Runnable r = new Runnable() {
                            @Override
                            public void run() {
                               // do something
                            }
};

Anyone else encountered this?

2
  • Yes, the default formatter does not suit everyone's tastes.
    – Anonymous
    Apr 4, 2012 at 14:47
  • Either of these answers acceptable?
    – sharakan
    Apr 17, 2012 at 17:11

3 Answers 3

6

Uncheck the "Align fields in columns" from the first tab of the Formatter

2

Depends on your eclipse settings. You can change the default formatting by clicking: window > preferences > java > code style > formatter.

1
  • which one? You can select from a dropdown which is default formatting - in your case the default will be Eclipse formatting[built-in].
    – asenovm
    Apr 4, 2012 at 20:20
1

In eclipse preferences, go to the formatter page (Window->Preferences, Java->Code Style->Formatter). Edit the formatting 'Profile'. Go to the 'Blank Lines' tab, and change the 'Before first declaration' value from 1 to 0.

FYI, this will change the formatting for ALL classes, not just anonymous ones. It'd be nice if it was more granular, but there it is.

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.