• Post Reply Bookmark Topic Watch Topic
  • New Topic

Float Wrapper Class -- accept double  RSS feed

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know why the Float wrapper class constructor allows you to send in a double as a param to the constructor ?

I figured it would have at least thrown a runtime error but it runs fine.

But...the valueOf() method in the wrapper class will throw compile error if you try to pass in a double primitive but will let you pass in a double in string format

 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The float class has a constructor for doubles:

And the valueOf method does the following:

Returns a Float object holding the float value represented by the argument string s.


The method takes the string as a float value, if the value can be represented by a float
But you have to call the valueOf method either with a string or a float. She is not defined for a double.

cheers Bob
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!