Why do you not declare several variables of the same type on the same line?

后端 未结 16 2225
梦谈多话
梦谈多话 2020-12-06 05:41

Why is it bad practice to declare variables on one line?

e.g.

private String var1, var2, var3

instead of:

private          


        
16条回答
  •  天命终不由人
    2020-12-06 05:51

    Relevance.

    Just because two variables are of type String does not mean they are closely related to each other.

    If the two (or more) variables are closely related by function, rather then variable type, then maybe they could be declared together. i.e. only if it makes sense for a reader of your program to see the two variables together should they actually be placed together

提交回复
热议问题