今天查看以前所写的代码,看到有一部分被人改了,代码如下:


if
(orgId != organizationUpdateReq.getOrgId()) { //orgId的类型为Integer,organizationUpdateReq.getOrgId()的返回值也是Integer
throw ParameterAssert.warpExcp(ErrorCodeConstants.WRONG_PARAMETER_NOT_ALLOW, "错误!"); 

}

一个很明显的错误,当时我的脑海中是这样想的:

Integer会自动拆箱进行比较,这样就变成了以下的代码:

if (orgId.intValue() != organizationUpdateReq.getOrgId().intValue()) {  //orgId的类型为Integer,organizationUpdateReq.getOrgId()的返回值也是Integer
throw ParameterAssert.warpExcp(ErrorCodeConstants.WRONG_PARAMETER_NOT_ALLOW, "错误!"); 

}

看来有些还是搞混了,Integer的比较是对象之间的比较,不会进行自动拆箱,拆箱和装箱的时机是发生在赋值操作中。

引以为戒!!!!错的太low了。

相关文章:

  • 2022-12-23
  • 2021-09-29
  • 2022-12-23
  • 2021-10-06
  • 2022-03-07
  • 2021-12-07
  • 2021-11-17
  • 2021-12-16
猜你喜欢
  • 2021-11-03
  • 2022-12-23
  • 2022-12-23
  • 2022-03-02
  • 2022-12-23
  • 2021-08-20
  • 2021-10-24
相关资源
相似解决方案