This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes assignment conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "assignment conversion " Watch "assignment conversion " New topic
Author

assignment conversion

Karel KoboojBot
Ranch Hand

Joined: Apr 09, 2004
Posts: 35
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.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
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


SCJP Tipline, etc.
Karel KoboojBot
Ranch Hand

Joined: Apr 09, 2004
Posts: 35
Thanks, after reading the JLS section again it states clearly that the expression should be constant. Making it final does indeed work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: assignment conversion
 
Similar Threads
ArrayList problem ...
AroundInvoke
about eclipse framework
Plugin
regarding overriding with var agrs