Files
codeql/java/ql/src/Language Abuse/UselessUpcast.qhelp
2018-08-30 10:48:05 +01:00

37 lines
1.1 KiB
XML

<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
In most situations, casting an instance of a derived type to a base type serves no purpose, since the conversion can be done implicitly. In such cases,
the redundant cast can simply be removed. However, an upcast is not redundant in the following situations:
</p>
<ul>
<li>It is being used to force a call to an overloaded callable that takes a parameter of the base type rather than one of the derived type.</li>
<li>It is being used to specify the type to use for the operands of a ternary expression.</li>
</ul>
<p>
Both of these special cases are illustrated in the example below. This rule ignores these
special cases and highlights upcasts which appear to be redundant.
</p>
</overview>
<recommendation>
<p>
Remove the unnecessary upcast to simplify the code.
</p>
</recommendation>
<example>
<p>The following code includes an example of a redundant upcast that would be highlighted by this rule.
In addition, three examples of upcasts that are required and are ignored by this rule.</p>
<sample src="UselessUpcast.java" />
</example>
</qhelp>