The return type of a ternary (or more correctly, conditional) expression where the second and third operands consist of one primitive and one corresponding boxed version, is that of the primitive.
(For a complete analysis of the type of the conditional operator, look at the Java Specifications 15.25.)
Since the second operand here, UNSPECIFIED_PARAMETER_KEY
, is a long
, and the third, value
is a Long
, Java has to unbox value
to a long
to evaluate the expression.
After this, a Long
is to be returned, so value
is immediately reboxed.
You can fix this by changing your constant UNSPECIFIED_PARAMETER_KEY
into a Long
.