This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes narrowing primitive conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "narrowing primitive conversion" Watch "narrowing primitive conversion" New topic
Author

narrowing primitive conversion

sriram sandhya
Greenhorn

Joined: Nov 05, 2002
Posts: 2
Hi,
I was trying to compile a statement.
int i = 20;
final int j = 20;
byte a = i; //Fails
byte b = j; //does not complain.
In the book I am reading the author says that since the final value of j is in the range of byte b, it won't complain. then why does the line before fails. Is it because we do not know the value of i for sure(unlike j) and it might go out of range of byte a?
Any help will be greatly appreciated
Sriramsandhya
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I think you are understanding the situation. The compiler can determine (and link) the value of the final variable at compile time. The other variable is not final, so the "link" cannot be made (and the value guaranteed) at compile time and so the compiler error.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
sriram sandhya
Greenhorn

Joined: Nov 05, 2002
Posts: 2
Thanks for the reply.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: narrowing primitive conversion