• Post Reply Bookmark Topic Watch Topic
  • New Topic

Type casting Doubt  RSS feed

 
kiruthigha rajan
Ranch Hand
Posts: 69
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
guyz i have a big doubt in implicit and explicit type casting.
consider the following code:
1.int a=11.121;
2.double b=100l;

System.out.println(a);
System.out.println(b);

in Line 1 a explicit type casting is needed where both of them(int and float) contains the same size ie is 32 bits.
in Line 2 there is a implicit casting has occurred where both of them(double and long) contains the same size ie is 64 bits.

then why float needs explicit casting and long doesnt need it?

thanks in advance
 
Sagar Dabas
Ranch Hand
Posts: 47
C++ Java PHP
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using the 2nd edition? Here is the 3rd edition chapter. You want to look for widening primitive conversions.
 
Sagar Dabas
Ranch Hand
Posts: 47
C++ Java PHP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Why are you using the 2nd edition? Here is the 3rd edition chapter. You want to look for widening primitive conversions.

Hmm, I just google jls conversions and pasted the first link which appeared.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google failed there, didn’t they. I got the 2nd edition link too. You ought to bookmark the most recent edition of the JLS. Actually there appears to be a 4th edition which I didn’t know about. I shall probably continue to quote the 3rd edition because it has nice links I can copy.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!