my dog learned polymorphism
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


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
 
Have you checked out Aspose?
 
subject: implicit casting with retun types
 
jQuery in Action, 3rd edition