java byte/short/char补充(了解)

1、在数学运算中会自动提升数据类型为 int

2、在基本赋值中,若右册的常量不超过取值范围,javac 添加 强制转换,否则报错

3、若右册 含有 变量 而不是直接使用常量相加,编译报错

例子

public class test{
    public static void main(String[] args){
        byte a = 10;
        byte b = 5;
        byte c;
        c = a+b;
        System.out.println(max);
    }
}

a + b => int + int =>15 int

原文地址:https://www.cnblogs.com/wt7018/p/12153866.html