[java]: redundant cast: treat switch expression branches separately (IDEA-269929)

GitOrigin-RevId: 4eecfab7aff32bc69164b740d1bd36f9a29b6cda
This commit is contained in:
Anna Kozlova
2021-05-24 22:41:49 +02:00
committed by intellij-monorepo-bot
parent 5a42eae302
commit 890efeaded
2 changed files with 31 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
import java.util.function.Predicate;
import java.util.*;
class RedundantCast {
private static void foo(final int matchType) {
@@ -14,4 +15,20 @@ class RedundantCast {
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<>();
};
}
}