Java


JAVA.CLASS.UIGC : Unnecessary Instantiation for GetClass (Java)

要旨

A class is only instantiated to get its class tag, instead of using its name and the .class pseudo-field.

It is often convenient to use a literal or a unique object instead of explicitly constructing new instances, when the same object is used many times, since distinct objects are created at each new statement, which affects the performance of the code. Moreover, objects used instead of literals are often short-lived and consequently must be claimed back from the garbage-collector.

プロパティ

クラス名 Unnecessary Instantiation for GetClass (Java)
日本語クラス名 Unnecessary Instantiation for GetClass (Java)
クラス分類 信頼性 (reliability)
ニーモニック JAVA.CLASS.UIGC
カテゴリー なし
対応言語 Java で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Unnecessary Instantiation for GetClass (Java)"

解決法

Use string literals instead of the creation of constant strings. Use factory methods or the automatic boxing mechanism instead of the instantiation of a primitive wrapper class.

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。