From the Oracle tutorial on Autoboxing, the two cases where boxing will occur are, when primitives are:
- Passed as a parameter to a method that expects an object of the corresponding wrapper class.
- Assigned to a variable of the corresponding wrapper class.
The expression being evaluated in your example (a.compareTo(d)
) does not fall in any one of those scenarios.
Theres some interesting additional information in the JCP proposal for autoboxing, describing the mechanics and rules for assignment conversion, method invocation conversion, and casting conversion.