eclipse 内联实现的接口缩进

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10013543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:57:58  来源:igfitidea点击:

Inline implemented interface indentation

javaeclipseinterfaceindentation

提问by Theodor

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 alotlike:

然后按CTRL+ SHIFT+ F(自动修复缩进),eclipse 将方法缩进很多,例如:

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

Anyone else encountered this?

有其他人遇到过这个吗?

采纳答案by asenovm

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

取决于您的日食设置。您可以通过单击来更改默认格式:窗口 > 首选项 > java > 代码样式 > 格式化程序。

回答by Erich Cervantez

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

从格式化程序的第一个选项卡中取消选中“对齐列中的字段”

回答by sharakan

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.

在eclipse首选项中,进入格式化程序页面(Window->Preferences,Java->Code Style->Formatter)。编辑格式“配置文件”。转到“空白行”选项卡,将“首次声明之前”的值从 1 更改为 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.

仅供参考,这将更改所有类的格式,而不仅仅是匿名类。如果它更细化就好了,但它就是这样。