是否有一个 checkstyle 规则可以捕获这样的东西:
double result = someInt / someOtherInt;
result
是 double(因此显然需要分数)但右侧会进行整数除法(向下舍入)。
有这样的东西吗?
最佳答案
没有,但是findbugs can :
ICAST: Integral division result cast to double or float (ICAST_IDIV_CAST_TO_DOUBLE)
This code casts the result of an integral division (e.g., int or long division) operation to double or float. Doing division on integers truncates the result to the integer value closest to zero. The fact that the result was cast to double suggests that this precision should have been retained. What was probably meant was to cast one or both of the operands to double before performing the division.
关于java - 可疑整数除法的检查样式规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58251183/