Java Coding standard: multiple variable declaration [closed]

♀尐吖头ヾ 提交于 2019-12-16 18:03:45

问题


Which of the following is best practice according to Java coding standards

public void function1(){
    int i1 = 0, i2 = 1, i3 = 2;
    // some code here
}

public void function1(){
    int i1 = 0;
    int i2 = 1;
    int i3 = 2;
    // some code here
}

Is there any practice which recommends the usage of first approach, for me its not good for readability but for others in my team it is good practice.


回答1:


Java does not regulate this, it's really a habit, depends on you and your team. I personally believe that 95% of he teams does not prefer this one-line declaration, it's not readable.



来源:https://stackoverflow.com/questions/26930181/java-coding-standard-multiple-variable-declaration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!