public class PatternInstanceOf { public void foo(Object o) { if (o instanceof String y) { System.out.println(y); } } }