Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Float wrapper takes double primitive implicitly.

 
Arnab Saha
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
toString() is not a static method in Float.
 
A Kumar
Ranch Hand
Posts: 980
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic