Integer to byte casting in Java

前端 未结 5 874
有刺的猬
有刺的猬 2021-01-18 18:43

In Java we can do

byte b = 5;    

But why can\'t we pass same argument to a function which accepts byte

myObj         


        
5条回答
  •  时光取名叫无心
    2021-01-18 19:15

    You must cast your argument 5 to type byte in your method testByte. Java looks specifically at the argument type.

    Change it to:

    myObject.testByte( (byte) 5);
    

提交回复
热议问题