mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
36 lines
1.4 KiB
HTML
36 lines
1.4 KiB
HTML
<html>
|
|
<body>
|
|
Reports "magic numbers": numeric literals that are not named by a constant declaration.
|
|
<p>Using magic numbers can lead to unclear code, as well as errors if a magic
|
|
number is changed in one location but remains unchanged not another. The numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 1000, 0L, 1L, 2L,
|
|
0.0, 1.0, 0.0F and 1.0F are not reported by this inspection.</p>
|
|
<p>Example:</p>
|
|
<pre><code>
|
|
void checkFileSize(long bytes) {
|
|
if (bytes > 1_048_576) {
|
|
throw new IllegalArgumentException("too big");
|
|
}
|
|
}
|
|
</code></pre>
|
|
<p>A quick-fix introduces a new constant:</p>
|
|
<pre><code>
|
|
static final int MAX_SUPPORTED_FILE_SIZE = 1_048_576;
|
|
|
|
void checkFileSize(long bytes) {
|
|
if (bytes > MAX_SUPPORTED_FILE_SIZE) {
|
|
throw new IllegalArgumentException("too big");
|
|
}
|
|
}
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
<p>Configure the inspection:</p>
|
|
<ul>
|
|
<li>Use the <b>Ignore constants in 'hashCode()' methods</b> option to disable this inspection within <code>hashCode()</code> methods.</li>
|
|
<li>Use the <b>Ignore in annotations</b> option to ignore magic numbers in annotations.</li>
|
|
<li>Use the <b>Ignore initial capacity for StringBuilders and Collections</b> option to ignore magic numbers used as initial capacity when constructing
|
|
<code>Collection</code>, <code>Map</code>,
|
|
<code>StringBuilder</code> or <code>StringBuffer</code> objects.</li>
|
|
</ul>
|
|
|
|
</body>
|
|
</html> |