问题
在调用 Java 方法(或在联编函数中)时,如果参数和参数类型都是原始类型,则不会使用宽化转换来定位正确的重载方法/构造函数。
示例
`
user=> (Integer. (byte 0))
java.lang.IllegalArgumentException: 未找到类 java.lang.Integer 的匹配构造函数 (NO_SOURCE_FILE:0)
上述情况发生是因为没有 Integer(byte) 构造函数,尽管它应该与 Integer(int) 匹配。
user=> (bit-shift-left (byte 1) 1)
Reflection warning, NO_SOURCE_PATH:3 - call to shiftLeft can't be resolved.
2`
In the above, a call is made via reflection to Numbers.shiftLeft(Object, Object) and its associated auto-boxing, instead of directly to the perfectly adequate Numbers.shiftLeft(long, int).
Workarounds:
Explicitly casting to the formal type.
Ancillary benefits of fixing:
It would also reduce the amount of method overloading, e.g., RT.intCast(char), intCast(byte), intCast(short), could all be removed, since such calls would pass to RT.intCast(int).