我们有一个旧的后端服务计算密码更改提醒。
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"?