From edb733f8352a132ea0621d1e7fb6fd881f779eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Thu, 23 May 2024 21:10:58 +0200 Subject: [PATCH] Add test for UnnecessaryCast --- .../rule/codestyle/xml/UnnecessaryCast.xml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UnnecessaryCast.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UnnecessaryCast.xml index ebac87a9f5..53072694c5 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UnnecessaryCast.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UnnecessaryCast.xml @@ -866,4 +866,26 @@ class MyClass { } ]]> + + Unboxing in lambda + 1 + 4 + mismatch = payload -> (int) payload; // nowarn: here the cast does a null check + RefSpecies i = t -> (int) t; // nowarn: here the cast does a null check + IntSpecies i = t -> (int) t; // warn: in this context t->t is equivalent because it will be unboxed + + interface VoidSpecies { + void doSomething(T t); + } + interface RefSpecies { + X foo(T t); + } + interface IntSpecies { + int foo(T t); + } + } + ]]> +