gurpeet singh wrote:i think the integer literals in java default to integer type(int). so even thought all those numbers are in the range of short they still are of the type int.
There is a rule regarding compile time constants being implicitly casted from int to short, provided that they are in range. However, this rule doesn't apply to method call conversions, so this is why it doesn't work here.
Joined: Nov 23, 2011
Henry Wong wrote:
Janki Shah wrote:How do I cast that to short?
By using the explicit cast operator --- meaning ..... "(short)" in front of the value / expression that you want to cast to short.