Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Wrapper's String Constructor  RSS feed

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code is not working and i fail to understand why!!!


I presume that java will invoke autoboxing
when i change the display method to accept one argument,it works.
please help me out or point me in the correct direction.

Thanks in advance

 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

when i change the display method to accept one argument,it works.


Can you show us how you change it ?
 
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I this code when we invoke method as it will give compiler error.
But when we invoke it using it run fines. I also don't know why auto boxing is not work here. Anybody know?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Autoboxing helps to turn primitives into wrappers. It doesn't work with Strings.
 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Boxing is intended to map to-and-from primitive types but String
is not a primitive. Consider this. If an int were passed to a method
that accepts only a String, boxing does not convert the int to a String.
I will convert it to an Integer type, however.

Jim ... ...
 
Sheriff
Posts: 21424
94
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jim Hoglund wrote:I will convert it to an Integer type, however.


Auto-boxing and auto-unboxing only occurs if it is necessary. If you pass an int and there is no method that takes an int,or an Integer (or broader like long, Number) the compiler will just refuse to compile the class.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!