You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] UnnecessaryCast: False positive for anonymous class in Stream.map() with toList() #6409
Description:
PMD reports UnnecessaryCast for a cast that is actually required for successful compilation when returning an anonymous class implementing an interface from a Stream.map() lambda expression followed by .toList().
The cast is necessary due to how Java's type inference handles anonymous classes - without it, the code fails to compile with a type incompatibility error.
changed the title [-][java] UnnecessaryCast false positive: Cast required for anonymous class in Stream.map() with toList()[/-][+][java] UnnecessaryCast: False positive for anonymous class in Stream.map() with toList()[/+]on Jan 22, 2026
Activity
[-][java] UnnecessaryCast false positive: Cast required for anonymous class in Stream.map() with toList()[/-][+][java] UnnecessaryCast: False positive for anonymous class in Stream.map() with toList()[/+]zbynek commentedon Jan 24, 2026
You don't need the cast if you use
Not sure if PMD should force you to do that though.
[java] Fix pmd#6409: UnnecessaryCast false positive for anonymous cla…