java - 可疑整数除法的检查样式规则?

标签 java checkstyle integer-division spotbugs

是否有一个 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/

相关文章:

Java3d。如何增加视野范围?

java - @Before 注释在 espresso 测试中被 kotlin 忽略?

java - 解决 Java Checkstyle 错误 : Name 'logger' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'

gradle - Checkstyle gradle检查样式时无法实例化AvoidConstantAsFirstOperandInConditionCheck

java - Checkstyle "Expected @param tag for ' id'"错误

java - 为什么整数 div 和 mod 向零舍入?

java - 将整数除以 12 并显示余数是奇数还是偶数

Java - 通过 "Reference Value"?检索值还是引用值?

assembly - 我如何获得负股息的正模

java - 在表单上设置相同大小的按钮