| Author |
Autoboxing
|
Ian Lubelsky
Ranch Hand
Joined: Feb 10, 2010
Posts: 49
|
|
I am trying to test a piece of code which converts a string to an integer through autoboxing.
This works:
But this doesn't
From what I read and understood, is the second method can now be written, even though the compiler will interpret it as the first example I gave. However, when I compile the second example, I get an Incompatible Types error. It says Found java.lang.String, but Required java.lang.Integer.
Would I just be better off doing a..... Integer value = Integer.parseInt(args[0]); instead?
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16684
|
|
Autoboxing is for the conversion of a primative type to its wrapper, and vice versa. It has nothing to do with String to Integer conversion.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Ian Lubelsky
Ranch Hand
Joined: Feb 10, 2010
Posts: 49
|
|
|
After re-reading the section, that is what I figured. So I'm just going to use: Integer value = Integer.parseInt(args[0]);
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32633
|
|
|
That looks good, but it might be preceded by a test like thisYou may also wish to test for a NumberFormatException.
|
 |
Vivek Saha
Greenhorn
Joined: Mar 03, 2010
Posts: 4
|
|
Can any one please help me to understand the concept of "AUTOBOXING & UNBOXING" .......................?
|
 |
Vivek Saha
Greenhorn
Joined: Mar 03, 2010
Posts: 4
|
|
IS following the SCJP 6 book by--- Kathy & Bert enough for securing 100% marks in da SCJP exam???
|
 |
Janeice DelVecchio
Saloon Keeper
Joined: Sep 14, 2009
Posts: 1611
|
|
Vivek, please start a new thread for your questions. Asking questions in someone else's thread is hijacking and not very nice to the original poster.
SCJP exam questions should be asked in the SCJP forum.
A simple google search of autoboxing and Java should get you started.
|
When you do things right, people won't be sure you've done anything at all.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
And while we're making remarks on your posts:
Vivek Saha wrote:IS following the SCJP 6 book by--- Kathy & Bert enough for securing 100% marks in da SCJP exam???
1) UseRealWords. Not "da" but "the".
2) Nothing can guarantee you a 100% score in any exam.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: Autoboxing
|
|
|