Files
openide/java/java-impl/resources/inspectionDescriptions/CastThatLosesPrecision.html
2025-02-05 04:43:28 +00:00

20 lines
892 B
HTML

<html>
<body>
Reports cast operations between primitive numeric types that may
result in precision loss.
<p>Such casts are not necessarily a problem but may result in difficult to
trace bugs if the loss of precision is unexpected.</p>
<p><b>Example:</b></p>
<pre><code>
int a = 420;
byte b = (byte) a;
</code></pre>
<!-- tooltip end -->
<p>Use the <b>Ignore casts from int to char</b> option to ignore casts from <code>int</code> to <code>char</code>.
This type of cast is often used when implementing I/O operations because the <code>read()</code> method of the
<code>java.io.Reader</code> class returns an <code>int</code>.</p>
<p>Use the <b>Ignore casts from int 128-255 to byte </b> option to ignore casts of constant values (128-255) from <code>int</code> to
<code>byte</code>.
Such values will overflow to negative numbers that still fit inside a byte.</p>
</body>
</html>