mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-03 03:37:58 +07:00
34 lines
1.1 KiB
Java
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<>();
|
|
};
|
|
}
|
|
} |