在Java中使用final关键字将类型从整数转换为字节 [英] Type cast issue from int to byte using final keyword in java
本文介绍了在Java中使用final关键字将类型从整数转换为字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public static void main(String[] args) {
final int a =15;
byte b = a;
System.out.println(a);
System.out.println(b);
}
在上面的代码中,当我从int转换为byte时,它没有给出编译时错误,但是当我从long转换为int时,却给出了编译时错误,为什么?
In above code when I am converting from int to byte it is not giving compile time error but when my conversion is from long to int it is giving compile time error, WHY?
public static void main(String[] args) {
final long a =15;
int b = a;
System.out.println(a);
System.out.println(b);
}
推荐答案
查看全文