Skip to main content

Practice ยท 3 of 3

Hunt the synthetic method

Implement static java.util.function.Comparator<String> lambdaComparator() that returns a comparator built from a **lambda** (e.g. (a, b) -> a.length() - b.length()), and static boolean hasSyntheticMember() that reflects over Solution.class.getDeclaredMethods() and returns true iff at least one method isSynthetic() (the lambda's desugared helper). Also implement static java.util.function.Comparator<String> anonymousComparator() using an **anonymous inner class** โ€” anonymous classes do not add synthetic *methods* to Solution. The tests verify both the sorting behavior and the reflective difference.

Difficulty: advanced

Back to lesson: Practice: JVM observable drills