• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help about wrapper class constructor

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It seems I can not pass int value to Byte constructor except explicitly casting and using String? Well, if data type matters, why I can pass double value to Float constructor? please help me out.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In general, methods will automatically widen a primitive data type in order to match an expected argument type, but they will not narrow it (because this could result in a loss of precision). This automatic widening is called method-call conversion.

Note that a literal int value can be assigned to a narrower primitive type if it is within range. However, this narrowing is only for assignments -- not method arguments.


The Float constructor is a little unusual (compared to the other numeric wrappers) because it's overloaded to accept a float or a double. In the case of a double, the argument is converted to a float before wrapping.
[ October 17, 2004: Message edited by: marc weber ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic