Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on Operators and Assignments

 
Sneha Neil
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is from Dan Chislom's site:
http://www.danchisholm.net/dec20/guide/chapter3/exam1.html

class GFC100 {
public static void main(String[] args) {
final short s1 = 1; // 1
final char c1 = 1; // 2
byte b1 = s1; // 3
byte b2 = c1; // 4
byte b3 = 1; // 5
byte b4 = 1L; // 6
byte b5 = 1.0; // 7
byte b6 = 1.0d; // 8
}}

I can understand the loss of precision errors for b4,b5 and b6.What I don't understand is why there are no such errors for b1 and b2? But, I get such an error when the final keyword is removed form s1 and c1. Can somebody please help me on this?

Thanks!
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may find that Dan Chisholm's reponse in this recent post helps.
 
Sneha Neil
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic