Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Denote method parameter as "short" primitive type

I have a method that accept one parameter of type short.

public void doSomething(short value) {
   //DO STUFF
}

And I can call it this way:

short value = 3;
doSomething(value);

But not this another one:

doSomething(3);

Why? Is there a way to denote that this parameter is a short and not an int?

like image 926
Héctor Avatar asked Mar 13 '26 15:03

Héctor


1 Answers

You can call it this way :

doSomething((short)3);

Without casting, 3 will always be an int literal.

like image 154
Eran Avatar answered Mar 16 '26 05:03

Eran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!