• 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!