什么是缩进接口的多个实现的公认做法

What is accepted practice for indenting multiple implementations of interfaces

如果我有一个 class 实现了许多侦听器,可接受的间距是多少?

现在我正在这样做:

public class MyClass 
    implements interface1,
    interface2,
    interface3,
    interface4,
    interface5 {

我会选择:

public class MyClass implements Interface1, Interface2, 
        Interface3, Interface4, Interface5 {

此处,第二行有两个缩进。

只需确保您组织中的每个人都使用相同的风格。

Here is a link to a Java Coding Convention from Sun Micro-systems way back in 1997. 虽然确实过时了,但这是我能在 java 中找到的描述编码约定的最佳 "official" 文档。它说要将新行对齐到与上面的行相同的bracket/space。

但是,对于没有公司强制编码约定的个人项目,我通常做的是换行、双制表符,然后输出与第一行大致相同的长度,然后根据需要重复。

简而言之,除非有人告诉您其他情况,否则请按照让您读得最好的方式去做。

编辑:Here is a link to the Google coding conventions for java.它所说的基本上是根据情况做任何事情,由编写它的程序员来决定是什么。