Java – type conversion required for function calls, with short data type variables as parameters

Whenever I use byte or short data types as method parameters, I need to explicitly convert the values I pass to these methods on method calls

To better explain:

void foo(short x)
{}
void main() {foo((short)32);}

If I don't use short here, a warning will be generated

method foo in class px cannot be applied to given types
required: byte
found: int

How can I make it better?

Solution

There is no way out

Java cannot write bytes or short text Any numeric text is an int value, and converting an int to short without a cast always generates a warning

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>