Java one line variable declaration?

java

Solution

This is simply a matter of taste and preference. However if you don't set guidelines it will become a hotbed of endless debate/arguments in most development teams, alongside Vim vs Emacs or IntelliJ vs Eclipse.

What I would recommend is setting coding standards for your team, and the simplest way to do this is to reference already-existing ones such as the Sun (now Oracle) Java Guidelines which in this case suggest using one declaration per line.

Here what Sun's definitive guide says about declarations[1]:

6.1 Number Per Line

One declaration per line is recommended since it encourages commenting. In other words,

int level; // indentation level
int size;  // size of table

is preferred over

int level, size;

Do not put different types on the same line. Example:

int foo,  fooarray[]; //WRONG!

[1] http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-141270.html#2991

Problem

In my Java class i am declaring variable like this ``` BigDecimal sumFeeBilled = new BigDecimal(0), sumPaid = new BigDecimal(0); ``` Or we have to declare like this in multiple line ``` BigDecimal sumFeeBilled = new BigDecimal(0); BigDecimal sumPaid = new BigDecimal(0); ``` Which one we should follow ?

Original source