This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

assignment question?? doubt?

 
srikanth reddy
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
float a = 1; // 1
float b = 1L; // 2
float c = 1F; //3
float d = 1.0; //4

hi,
4 wouldnt compile as ur trying to assign an double value to a float...

byte b3 = 1; // 5
byte b4 = 1L; // 6
byte b5 = 1.0; // 7
byte b6 = 1.0d; // 8

what i feel after seeing these expressions is ..
uptil int if its a constant it can assign to any value....as far as it is in the range of the left hand operand...
but after that for long ,float,double it sees whether they can assignable to appropriate primitive...

i got this doubt coz line 6 7 8 generate compile error,i thought they are compile time constants so they cub be easily fit into it...

please clarify
 
Roel De Nijs
Sheriff
Posts: 10591
140
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
about this line float d = 1.0; //4
you said yourself: "4 wouldnt compile as ur trying to assign an double value to a float..."

what's the difference between that line and following 2 lines (except for the left thing being a byte instead of a float)
byte b5 = 1.0; // 7
byte b6 = 1.0d; // 8

indeed, there is no difference.

for line 6 you're telling the compiler you are using a long and so you try assigning a long to a byte, which also don't work without using explicit cast
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic