J.VII · Java 25 practice question
A developer has a variable of type Box<Box<String>> and wants to match it with a nested record pattern using instanceof. How does the Java 25 compiler handle omitting type arguments on both the outer and inner Box patterns?
Check answer and explanation
Correct answer: The compiler infers the full parameterized types for both the outer and inner record patterns
Explanation
The compiler infers the full parameterized types for both the outer and inner record patterns, resolving Box(Box(var s)) to Box<Box<String>>(Box<String>(var s)).
Common trap
It is easy to assume type arguments must be written on the outer pattern like diamond syntax, but JEP 440 allows dropping them on both levels. The compiler does not degrade omitted record pattern type arguments to raw types with Object.
Source: JEP 440: Record Patterns — Description
Checked against the cited text on 2026-11-25.