Java - short and casting

后端 未结 3 2022
眼角桃花
眼角桃花 2020-12-06 01:53

I have the following code snippet.

public static void main(String[] args) {
 short a = 4;
 short b = 5;
 short c = 5 + 4;
 short d = a;
 short e = a + b; //          


        
3条回答
  •  时光取名叫无心
    2020-12-06 02:52

    The result of an arithmetic operation on short values is always int. test(7) doesn't work, since you haven't said that 7 is of type short. The compiler should be a bit smarter here.

提交回复
热议问题