| Author |
Integer class
|
Nazma Panjwani
Greenhorn
Joined: Jan 17, 2010
Posts: 14
|
|
Hi,
If you instantiate the Integer class passing in a certain value such as 60...is it possible to change that value to something else later on?
Thanks
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
The object itself can never change anymore. You cannot modify any of its fields, nor call any method that changes it. You can still change the value the reference points to. For instance:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Marcos Stoppa
Greenhorn
Joined: Jan 19, 2010
Posts: 4
|
|
At Java 5, was added the called autoboxing. With autoboxing you can create a new Wrapper object, with a new value, without manually boxing and unboxing it.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
I know, but I set up my Eclipse to warn against it. Autoboxing is not a problem, but autounboxing is a potential NullPointerException waiting to happen if you're not careful. Because you're not dereferencing anything yourself it will be harder to find the culprit.
|
 |
Nazma Panjwani
Greenhorn
Joined: Jan 17, 2010
Posts: 14
|
|
Marcos Stoppa wrote:At Java 5, was added the called autoboxing. With autoboxing you can create a new Wrapper object, with a new value, without manually boxing and unboxing it.
Hey,
It doesn't work, since i is already defined......
|
 |
Marcos Stoppa
Greenhorn
Joined: Jan 19, 2010
Posts: 4
|
|
Oooops, sorry. My fault.
The correct is:
Thanks Nazma!
|
 |
 |
|
|
subject: Integer class
|
|
|