class X { void expressions(Object obj) { boolean b1 = obj instanceof String s && s.isEmpty(); boolean b2 = !(obj instanceof String s) && s.isEmpty(); boolean b3 = obj instanceof String s || s.isEmpty(); boolean b4 = !(obj instanceof String s) || s.isEmpty(); boolean b5 = obj instanceof String s ? s.isEmpty() : obj == null; boolean b6 = !(obj instanceof String s) ? obj == null : s.isEmpty(); boolean b7 = obj instanceof String s ? s.isEmpty() : s.isEmpty(); boolean b8 = !(obj instanceof String s) ? s.isEmpty() : s.isEmpty(); } void twoPatterns(Object o1, Object o2) { if (o1 instanceof String s1 && o2 instanceof String s2 && s1.startsWith(s2)) {} if ((o1 instanceof String s1 && o2 instanceof String s2) && s1.startsWith(s2)) {} if (o1 instanceof String s1 && (o2 instanceof String s2 && s1.startsWith(s2))) {} if (o1 instanceof String s1 && !(o2 instanceof String s2) && s1.startsWith(s2)) {} } void polyadicInCondition(Object o1, Object o2) { boolean b1 = o1 instanceof String s1 && o2 instanceof String s2 ? s1.isEmpty() && s2.isEmpty() : false; boolean b2 = o1 instanceof String s1 && !(o2 instanceof String s2) ? s1.isEmpty() : s2.isEmpty(); } void ifThenSimple(Object o) { if (o instanceof String s) { System.out.println(s.trim()); } else { System.out.println(s.trim()); } if (!(o instanceof String s)) { System.out.println(s.trim()); } else { System.out.println(s.trim()); } } interface Node { Object next(); String name(); } void whileSimple(Object o) { while (o instanceof Node n) { o = n.next(); } } void whileNot(Object o) { while (!(o instanceof Node n)) { o = n.next(); } } void forSimple(Object o) { for (; o instanceof Node n; o = n.next()) { System.out.println(n.name()); } } }