Setting Short Value Java

后端 未结 4 620
死守一世寂寞
死守一世寂寞 2020-11-28 11:36

I am writing a little code in J2ME. I have a class with a method setTableId(Short tableId). Now when I try to write setTableId(100) it gives compil

4条回答
  •  情深已故
    2020-11-28 12:16

    Generally you can just cast the variable to become a short.

    You can also get problems like this that can be confusing. This is because the + operator promotes them to an int

    Casting the elements won't help:

    You need to cast the expression:

提交回复
热议问题