问题
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