缩进多个接口实现的公认惯例是什么

时间:2016-05-04 23:07:15

标签: java interface standards indentation

如果我有一个实现了许多侦听器的类,那么可接受的间距是什么?

现在我正在这样做:

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

2 个答案:

答案 0 :(得分:1)

我会选择:

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

这里,第二行有两个缩进。

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

答案 1 :(得分:0)

Here is a link to a Java Coding Convention from Sun Micro-systems way back in 1997.虽然确实过时了,但这是描述我能找到的java编码约定的最佳“官方”文档。它表示将新线对齐到与上面一行相同的括号/空格。

然而,我通常对没有公司强制执行编码约定的个人项目所做的是新行,双标签,然后出去与第一行大致相同的长度,然后根据需要重复。

简而言之,除非有人告诉你,否则只要做一些让你阅读最好的东西。

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

相关问题