java 变量声明,Java一行变量声明?

本文讨论了在Java编程中,应该选择单行还是多行声明变量的问题。作者建议团队应设定统一的编码标准,引用如Sun(现Oracle)Java指南,这些指南推荐每行只声明一个变量,以鼓励注释并提高代码可读性。
摘要由CSDN通过智能技术生成

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 ?

解决方案

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!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值