Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Float  wrapper takes double primitive implicitly. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Float  wrapper takes double primitive implicitly." Watch "Float  wrapper takes double primitive implicitly." New topic
Author

Float wrapper takes double primitive implicitly.

Arnab Saha
Greenhorn

Joined: Nov 08, 2005
Posts: 10
Why is it so?
Float f1 = new Float(1.24); //Gives no compilation error

while,
String s1 = Float.toString(1.24);//Gives compilation error

Are there other situations for Wrapper classes where there is
like this anomally.Please let me know.
Lakshmanan Arunachalam
Ranch Hand

Joined: Nov 02, 2005
Posts: 99
toString() is not a static method in Float.


Regards<br />Lakshmanan<br />IBM-OOAD & UML, SCEA-I
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Hi..

Float f1 = new Float(1.24);

Float has three constructors..

Float(float value)
Float(double value)
Float(String value)

Yours is the second constructor..


toString() is not a static method in Float.



toString() is not a static method but
toString(float value) is a static method

Here in your program you have passed double....try passing a float value..

Float.toString(1.24f);

See the result

Regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Float wrapper takes double primitive implicitly.