I am trying to call a function that requires a short value. The following works:
i.setDamage((short) 10);
However, this does not:
i.setDamage(10S);
According to the IDE I am using, this should work. Why does it not? I am using Maven and Java 7.
According to the Java Language Specification, Section 3.10.1, the only integer type suffix for integer literals is
L
(or lower casel
).You'll just have to stick with a cast. (Although you may be able to just use the integer literal without a cast if the value is in range.)