File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android 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
 
Similar Threads
Question from New Boone
Which eat method and why ??
Reference Types and Instance Types
Why this Output?
method overriding