Inspectopedia Help

Overly strong type cast

Reports type casts that are overly strong. For instance, casting an object to ArrayList when casting it to List would do just as well.

Note: much like the Redundant type cast inspection, applying the fix for this inspection may change the semantics of your program if you are intentionally using an overly strong cast to cause a ClassCastException to be generated.

Example:

interface Super { void doSmth(); } interface Sub extends Super { } void use(Object obj) { // Warning: ((Super)obj).doSmth() could be used ((Sub)obj).doSmth(); }

Use the checkbox below to ignore casts when there's a matching instanceof check in the code.

Inspection options

Option

Type

Default

Ignore casts with a matching instanceof expression

Checkbox

false

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023