Redundant Type Cast

ID

java.redundant_cast

Severity

low

Remediation Complexity

auto_fix

Remediation Risk

low

Remediation Effort

low

Resource

Code Smell

Language

Java

Tags

code-style

Description

Reports type casts where the expression already has the target type, making the cast redundant.

Rationale

A cast to the same type the expression already holds has no effect at runtime and adds visual noise. It often indicates a copy-paste mistake or a misunderstanding of the expression’s type:

String s = "hello";
String t = (String) s;   // Redundant: s is already String

int i = 42;
int j = (int) i;         // Redundant: i is already int

Remediation

Remove the unnecessary cast:

String t = s;
int j = i;