• 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

Doubt regarding Wrapper Constructor

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers.....I have been following K & B for SCJP 1.4.

While creating Wrapper objects, arg takes a primitive of the type being constructed as per book.

but i tried creating Float wrapper objects that works fine even when we pass double/char/integer.....i dint get it??

Also, if its the case then creating an Integer object with Long as arg doesn't work....so why does it differ from float constructors which can take double as an arg....??

Am confused.....please do let me know what all args are compatible while creating wrappers for int and float???

Thanks
Kirti
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

but i tried creating Float wrapper objects that works fine even when we pass double/char/integer.....i dint get it??



It's a quirk of the Float class. There is an overloaded constructor that takes a double. As for integer, char, etc., that is because those types can be implicitly casted to a float.

Also, if its the case then creating an Integer object with Long as arg doesn't work....so why does it differ from float constructors which can take double as an arg....??



Unfortunately, the Integer class doesn't have an overloaded constructor that takes a long.

The JavaDoc is the best source here. Take a look at the Integer and Float classes, and see what constructors they support.

Henry
 
kirti tiwari
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Henry for your help!!!

Regards
Kirti
 
reply
    Bookmark Topic Watch Topic
  • New Topic