• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Float Wrapper Class -- accept double

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic