【仅供内部供应商使用,不提供对外解答和培训】

Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
public class DateWork { 
   private int remainDays = 10;//剩余的天数 
 
   public void calculateNameWithData(Data data) { 

   } 
}
Note

两个对象做equals判断时,必须使用ComparatorUtils.equals(Object obj1, Object obj2)来进行判断,可以避免各种空指针错误。如果是明确的字符串比较,可以不使用工具方法。

Code Block
title

...

不推荐
if (a.equals(b)) {
    // do something
}

...

Code Block
title正确
if (ComparatorUtils.equals(a, b)) {
    // do something
}

同样正确:下面的写法同样正确,并且是推荐的写法,因为字符串"abcde"是确定不为null的:

Code Block
title同样正确
if

...

 ("abcde".equals(op)) {
   // do something
}
Note

任意一个方法的长度不得超过50行。过长的方法不方便写单元测试后期的维护以及扩展,尽量做到一个方法只做一件单一的事情。

Note

公共API方法的参数不要超过4个,过多的参数不利于方法的理解和使用。除了关于HTTP请求之类的本身就带了Response和Request两个参数的方法除外。

Code Block
if,if-

...

else,for,while,do和switch语句后面必须跟上"大括号{}

...

"。主要是为了清晰的表名语句的作用范围和避免一些低级的错误。
Code Block
title不推荐
if (statement) return;

...

Code Block
title正确
if (statement) { 

...

   return; 
}
Note
尽量使程序结构能更正确简洁的表达你的意图。如果能不用条件判断,则不要使用条件判断。

...

Code Block
title不推荐
if (booleanExpression) {
     return true; 
} else { 
    return false;
}
Code Block

...

title正确
return booleanExpression;

 

 
严格控制方法/变量的权限,只在当前类使用的方法/变量,必须使用private修饰符。

...