This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Final variables and downcasting

 
del boy
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I do not understand why when we try to assign a FINAL variable of type primitive data type (eg. int ) to a lower type (eg. byte)
the compiler WILL NOT throw an error, only IF the value of the final variable is within range.... if you look at case 2 below if the variable
g is NOT final will have compiler error: POSSIBLE LOSS OF PRECISION, same with case 3 when final var is larger than data range of byte.
MY QUESTION IS: WHY with final variable in the first case we DO NOT have to explicitly downcast ???
Many thanks in advance!
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the compiler knows that the final variable can never be changed to something else so it will never be beyond the range.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic