<div dir="ltr">Hello!<div><br></div><div>I noticed that the following program is compilable without errors using OpenJDK 25 javac:<br><div><br></div><div>private static <X extends Integer> void add(X x) {<br>    System.out.println(+x);<br>}<br><br>void main() {<br>    add(10);<br>}<br></div><div><br></div><div>I wonder if it's correct. The JLS 15.15.3 says [1]:<div><div><br>The type of the operand expression of the unary + operator must be a type that is convertible (§5.1.8) to a primitive numeric type, or a compile-time error occurs.<br><br></div><div>The JLS 5.1.8, in turn, says [2]:</div><div><br></div><div>Unboxing conversion treats expressions of a reference type as expressions of a corresponding primitive type. Specifically, the following eight conversions are called the unboxing conversions:<br>...</div><div>From type Integer to type int<br>...</div><div>At run time, unboxing conversion proceeds as follows:</div><div>...</div><div>If r is a reference of type Integer, then unboxing conversion converts r into r.intValue()<br><br></div><div>In my case, the type of reference is X, rather than Integer. So my question, should I read 'type Integer' here as 'type Integer, or any generic type whose upper bound is type Integer'? In other words, should we assume that the X type declared as `X extends Integer` is convertible to a primitive numeric type? It looks like, here a widening reference conversion (5.1.5) happens before an unboxing conversion, but 15.15.3 does not say about widening reference conversion. I've also checked 5.6 "Numeric contexts", but it also does not mention that before unboxing conversion, a widening reference conversion might occur. </div><div><br></div><div>Could anybody please clarify whether the compiler is wrong or I read the specification incorrectly? Thank you in advance!</div><div><br></div><div>With best regards,</div><div>Tagir Valeev</div><div><br></div><div>[1] <a href="https://docs.oracle.com/javase/specs/jls/se25/html/jls-15.html#jls-15.15.3">https://docs.oracle.com/javase/specs/jls/se25/html/jls-15.html#jls-15.15.3</a></div><div>[2] <a href="https://docs.oracle.com/javase/specs/jls/se25/html/jls-5.html#jls-5.1.8">https://docs.oracle.com/javase/specs/jls/se25/html/jls-5.html#jls-5.1.8</a></div></div></div></div></div>