import java.util.function.Predicate; import java.util.*; class RedundantCast { private static void foo(final int matchType) { Object o = switch (matchType) { default -> (Predicate) target -> target == null; }; Predicate o1 = switch (matchType) { default -> (Predicate) target -> target == null; }; Predicate o2 = switch (matchType) { default: yield (Predicate) target -> target == null; }; } @SuppressWarnings("unchecked") List getList1(int x) { return (List) switch(x) { case 0 -> new ArrayList<>(); default -> new ArrayList(); }; } @SuppressWarnings("unchecked") List getList2(int x) { return (List) 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(); } }