Win a copy of Microservices in Action this week in the Web Services 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:
  • 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

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: 21466
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!