For more information on Method Invocation Conversion see JLS - Section No. 5.3 .
Method invocation contexts allow you to use one of the following values:
- an identity conversion (ยง5.1.1) - a widening primitive conversion (ยง5.1.2) - a widening reference conversion (ยง5.1.5) - a boxing conversion (ยง5.1.7) optionally followed by widening reference conversion - an unboxing conversion (ยง5.1.8) optionally followed by a widening primitive conversion.
So, your first call ( int to double ) will work fine in accordance with rule No. 2.
But the second call ( double to int ) will give a compiler error, in accordance with the statement below in the same section: -
If the type of the expression cannot be converted to the type parameter by conversion allowed in the context of the method call, a compile-time error occurs.
source share