我在Java中有以下代码:
void foo(int a) { ... }
void bar() {
Long x = 42;
foo(x); // Compile error: "Method foo(int)
// is not applicable for the argument (long)"
foo((long) x); // Same as before
foo((int) x); // Compile error: "Cannot cast Long to int"
foo((int) (long) x); // OK, but strange and confusing
}
有没有更好的办法?