Yes, you should suspect something is wrong with the statement.
int sum = value + 41; // sum is an int, value is an object reference, 41 is an int literal
But the statement is correct and does what you want. (The program is not very sensible, though, since there is no real need for the Wrapper.)
The Java compiler figures out what you want and
creates bytecode that extracts the int from value,
performs the addition,
and puts the result in the sum.
Extracting a primitive value from a Wrapper is called unboxing.
Here is some more suspicious code.
The way to compute the sine of an angle (in radians) is
Math.sin( theta ) where theta is a double.
But in the code, angle is an object reference.
For more about Java math functions see chapter 13.
public class ShowSine
{
public static void main ( String[] args )
{
Double angle = 0.5; // angle in radians (auto boxed)
double sine = Math.sin( angle ); // compute sine of the angle
System.out.println( "sine of: " + angle " is " + sine );
}
}
Will the above code work?