This is a question about choosing the "most specific" method.
According to
JLS - 15.12.2.2, "one method declaration is more specific than another if any invocation handled by the first method could be passed on to the other one without a compile-time type error."
Let's consider your
second example first, because this is one that works. Here, the methods are overloaded with (int, long, int) and (long, long, int). In this case, the first method can be identified as more specific, because each of its argument types can be converted (upcast or widened) to the
corresponding argument type in the second method. In particular...
Now let's consider why your
first example does not work. Here, the methods are overloaded with (int, long, int) and (long, int, long). This is ambiguous because
neither set of argument types can be converted to the other. In particular, the first method is NOT more specific because its second argument is a long, which
cannot be converted to an int...
Also, the second method is NOT more specifc because its first and third arguments are both longs, which
cannot be converted to ints...
Because this is ambiguous, a compiler error results.