Challenge 3: instanceof Pattern Matching Without an Explicit Cast — Possible Solution ==================================================================== PatternDemo.java: public class PatternDemo { static void describe(Object obj) { if (obj instanceof String s) { System.out.println("String length: " + s.length()); } else if (obj instanceof Integer i) { System.out.println("Integer doubled: " + (i * 2)); } else { System.out.println("Unrecognized type"); } } public static void main(String[] args) { describe("hello"); describe(21); describe(3.14); } } Output: String length: 5 Integer doubled: 42 Unrecognized type Explanation: `obj instanceof String s` checks obj's type AND binds it to a new variable `s` of type String in the very same expression -- no separate `String s = (String) obj;` cast line is needed, unlike the old two-step check-then-cast approach. The same pattern applies to the Integer branch with `i`, which is auto-unboxed for the multiplication. WHY THIS WORKS AS AN ANSWER ------------------------------ Both branches use the pattern-matching form of instanceof the chapter introduces, binding directly to a typed variable with no explicit cast anywhere in the method, exactly the "no separate cast needed" behavior the chapter describes.