Add test for UnnecessaryCast

This commit is contained in:
Clément Fournier
2024-05-23 21:10:58 +02:00
parent 1bde246b8b
commit edb733f835

View File

@ -866,4 +866,26 @@ class MyClass {
}
]]></code>
</test-code>
<test-code>
<description>Unboxing in lambda</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>4</expected-linenumbers>
<code><![CDATA[
public abstract class Example {
VoidSpecies<Integer> mismatch = payload -> (int) payload; // nowarn: here the cast does a null check
RefSpecies<Integer, Object> i = t -> (int) t; // nowarn: here the cast does a null check
IntSpecies<Integer> i = t -> (int) t; // warn: in this context t->t is equivalent because it will be unboxed
interface VoidSpecies<T> {
void doSomething(T t);
}
interface RefSpecies<T, X> {
X foo(T t);
}
interface IntSpecies<T> {
int foo(T t);
}
}
]]></code>
</test-code>
</test-data>