Files
openide/java/java-impl/resources/inspectionDescriptions/CharsetObjectCanBeUsed.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

23 lines
853 B
HTML

<html>
<body>
Reports methods and constructors in which constant charset <code>String</code> literal (for example, <code>"UTF-8"</code>) can be replaced with
the predefined <code>StandardCharsets.UTF_8</code> code.
<p>The code after the fix may work faster, because the charset lookup becomes unnecessary.
Also, catching <code>UnsupportedEncodingException</code> may become unnecessary as well. In this case,
the catch block will be removed automatically.</p>
<p>Example:</p>
<pre><code>
try {
byte[] bytes = "str".getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
}
</code></pre>
<p>After quick-fix is applied:</p>
<pre><code>
byte[] bytes = "str".getBytes(StandardCharsets.UTF_8);
</code></pre>
<!-- tooltip end -->
<p>The inspection is available in Java 7 and later.</p>
<p><small>New in 2018.2</small></p>
</body>
</html>