如何解决 Sonarqube 问题“将此减法运算的一个操作数转换为‘long’。”?

问题描述 投票:0回答:0

我们有一个旧的后端服务计算密码更改提醒。

 import java.util.concurrent.TimeUnit;

 int daysBeforePasswordExpires = 60;
 Integer daysBeforeReminder = 30;
 long daysLeftToRemind = TimeUnit.DAYS.toMillis(daysBeforeReminder  - daysLeftToRemind );

这段代码确实有效,但我需要解决 Sonarqube 发现的问题

  Cast one of the operands of this subtraction operation to a "long".

指向

long daysLeftToRemind = TimeUnit.DAYS.toMillis(daysBeforeReminder  - daysLeftToRemind );

我做了以下更改

long daysLeftToRemind = TimeUnit.DAYS.toMillis(daysBeforeReminder  - (long) daysLeftToRemind );
,Sonarqube 问题消失了。

但我担心这会影响我的更改计算提醒前剩余天数的方式。

How to solve Sonarqube issue with result of Cast one of the operands of this subtraction operation to a "long"?

java sonarqube
© www.soinside.com 2019 - 2024. All rights reserved.