Hi, according to the JLS (p. 66) I think the following block of code should be allowed
but my IDE (Eclipse) reports this as an error. Did I make a wrong interpretation of the JLS or is the Eclipse IDE a bit too restrictive in this case ? Thanks.
posted 11 years ago
This is an error. You can not implicitly cast a short (2 bytes) to a byte (1 byte). However, if the value you are assigning is a constant (and therefore known at compile time), the assignment is allowed, as long as the value fits into the destination type. Try making your short final - that will make it a compile-time constant and I believe your code will work. Corey