我在Java中有以下方法:
private static short charToShort_1() {
return 's';
}
private static char shortToChar_1() {
return ((short) 15);
}
private static short charToShort_2() {
char ch = 's';
return ch;
}
private static char shortToChar_2() {
short number = 15;
return number;
}
Run Code Online (Sandbox Code Playgroud)
为什么“charToShort_1”和“shortToChar_1”编译成功?
同时,最后两个方法“charToShort_2”和“shortToChar_2”无法编译(因为需要显式转换)。