Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/switchExpressions/RedundantCastInSwitchBranch.java
Anna Kozlova 890efeaded [java]: redundant cast: treat switch expression branches separately (IDEA-269929)
GitOrigin-RevId: 4eecfab7aff32bc69164b740d1bd36f9a29b6cda
2021-05-25 06:42:14 +00:00

34 lines
1.1 KiB
Java

import java.util.function.Predicate;
import java.util.*;
class RedundantCast {
private static void foo(final int matchType) {
Object o = switch (matchType) {
default -> (Predicate<Object>) target -> target == null;
};
Predicate<Object> o1 = switch (matchType) {
default -> (<warning descr="Casting 'target -> {...}' to 'Predicate<Object>' is redundant">Predicate<Object></warning>) target -> target == null;
};
Predicate<Object> o2 = switch (matchType) {
default:
yield (<warning descr="Casting 'target -> {...}' to 'Predicate<Object>' is redundant">Predicate<Object></warning>) target -> target == null;
};
}
@SuppressWarnings("unchecked")
<T> List<T> getList1(int x) {
return (List<T>) switch(x) {
case 0 -> new ArrayList<>();
default -> new ArrayList<Integer>();
};
}
@SuppressWarnings("unchecked")
<T> List<T> getList2(int x) {
return (<warning descr="Casting 'switch(x) { ...' to 'List<T>' is redundant">List<T></warning>) switch(x) {
case 0 -> new ArrayList<>();
default -> new ArrayList<>();
};
}
}