谁能告诉我为什么这种显式转换会产生不同的结果,即使 short/char 的大小都是 16 位?
package jh;
public class Main {
public static void main(String[] args) {
byte b = (byte)255;
System.out.println("Size of short: " + Short.SIZE);
System.out.println("Size of char: " + Character.SIZE);
System.out.println((int)((short)b));
System.out.println((int)((char)b));
}
}
输出:
Size of short: 16
Size of char: 16
-1
65535