File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Wrapper's String Constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Wrapper Watch "Wrapper New topic
Author

Wrapper's String Constructor

Jitendra Jha
Ranch Hand

Joined: Jan 28, 2007
Posts: 91
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


Jitendra
SCJP1.5
SCWCD1.5
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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

Can you show us how you change it ?


[My Blog]
All roads lead to JavaRanch
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

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?


Life is easy because we write the source code.....
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Autoboxing helps to turn primitives into wrappers. It doesn't work with Strings.
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
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 ... ...


BEE MBA PMP SCJP-6
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrapper's String Constructor