Numeric cast that loses precision
Reports cast operations between primitive numeric types that may result in precision loss.
Such casts are not necessarily a problem but may result in difficult to trace bugs if the loss of precision is unexpected.
Example:
Use the Ignore casts from int to char option to ignore casts from int
to char
. This type of cast is often used when implementing I/O operations because the read()
method of the java.io.Reader
class returns an int
.
Use the Ignore casts from int 128-255 to byte option to ignore casts of constant values (128-255) from int
to byte
. Such values will overflow to negative numbers that still fit inside a byte.
Inspection options
Option | Type | Default |
---|---|---|
Ignore casts from int to char | Checkbox | false |
Ignore casts from int 128-255 to byte | Checkbox | false |
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |