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

implicit casting with retun types

 
Angela lewis
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code works fine


But this gives an error: Possible loss of precision


float is smaller than long (in number of bits) so is byte.
Why can we return one and not another?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the second example, you're actually trying to return a long from a method that can only return a byte!

In addition, when it comes to narrowing and widening conversions, I'd suggest reading this.
 
Angela lewis
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Corey McGlone:
In the second example, you're actually trying to return a long from a method that can only return a byte!

In addition, when it comes to narrowing and widening conversions, I'd suggest reading this.


But even in the first example i am returning a long when it can return a float.
float is 32 bits and long is 64 bits. Then why does that compile.
 
Angela lewis
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition, when it comes to narrowing and widening conversions, I'd suggest reading this.


Thank You so much Corey.
That was too good.
You are great
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic