java理解“可能丢失所需的精度字符字节”
class A {
public static void main(String [] varun) {
byte b = 65;
char ch = b;
System.out.println(ch);
}
}
为什么它会给出一个错误:
possible loss of precision
required char
found byte
你可以在下面搜索框中键入要查询的问题!
class A {
public static void main(String [] varun) {
byte b = 65;
char ch = b;
System.out.println(ch);
}
}
为什么它会给出一个错误:
possible loss of precision
required char
found byte
# 1 楼答案
Add as explicit cast as byte只取一个字节,char在java中为两个字节,而隐式类型转换不适用于byte和char
使用
# 2 楼答案
字节长为1字节,而字符长为2字节,因此它们不兼容。你需要使用铸造: