This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes implicit casting with retun types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "implicit casting with retun types" Watch "implicit casting with retun types" New topic
Author

implicit casting with retun types

Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100
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

Joined: Dec 20, 2001
Posts: 3271
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.


SCJP Tipline, etc.
Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100
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

Joined: Mar 01, 2004
Posts: 100
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: implicit casting with retun types