Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

type casting required on function calls taking short datatype variable as a parameter

Whenever I use byte or short data type as a method parameter, on method calls, I am required to explicitly cast the values I pass to those methods.

To better explain:

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

If I dont use short here then warning is generated.

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

How can I get it better?

like image 919
Rajat Gupta Avatar asked May 22 '26 18:05

Rajat Gupta


1 Answers

No way out.

Java doesn't have a way to code byte or short literals. Any number literal is an int value and converting an int to a short without casting always creates a warning.

like image 94
Andreas Dolk Avatar answered May 25 '26 08:05

Andreas Dolk