• Post Reply Bookmark Topic Watch Topic
  • New Topic

literals problem  RSS feed

 
Manish Sahni
Ranch Hand
Posts: 41
Java Netscape Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator





please help.... i can't understand...why the second one works..?
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
manish sahni wrote:




please help.... i can't understand...why the second one works..?


It works because of the final keyword. In your first one the compiler cannot guarentee that the value of s will always be able to fit within a byte. However, when you declare s as a final and it has a value that can fit in a byte, it will succeed because the value of s cannot change and will always fit within a byte.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!