Files
Bas Leijdekkers b9a6e40f0c Java: render array initializer expressions, switch expressions and instanceof expression correctly
GitOrigin-RevId: aad22125d6c8cbea4c398282a0eabb429c65e735
2022-11-16 19:42:12 +00:00

42 lines
1.3 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<>();
};
}
void castForFunctionalExpression(String s) {
(switch (s) {
case "a" -> (Runnable)() -> System.out.println("a");
case "b" -> (Runnable)() -> System.out.println("b");
default -> throw new IllegalArgumentException();
}).run();
}
}