Why can we not pass a char value as a argument to any method that accepts a short parameter
因为在调用上下文中没有从char到short的隐式转换.
whereas we can pass a char value to another method whose parameter is of int type?
那是因为在调用上下文中有一个从char到int的隐式转换.
Why does type casting not take place from char to short, given that the sizes are equal? I hope short can also store as much values as short can.
虽然char和short的大小相同,但char是无符号的,而short是有符号的.这就是为什么没有从char到short的隐式转换.
从char toint的转换是扩展的原始转换(JLS 5.1.2),而从char到short的转换是缩小的原始转换(JLS 5.1.3).特别是(强调我的):
A narrowing conversion of a char to an integral type T likewise simply discards all but the n lowest order bits, where n is the number of bits used to represent type T. In addition to a possible loss of information about the magnitude of the numeric value, this may cause the resulting value to be a negative number, even though chars represent 16-bit unsigned integer values.