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 Integer class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Integer class" Watch "Integer class" New topic
Author

Integer class

Nazma Panjwani
Greenhorn

Joined: Jan 17, 2010
Posts: 17
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: 19680
    
  18

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 - OCEEJBD 6
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: 19680
    
  18

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: 17
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!

 
jQuery in Action, 2nd edition
 
subject: Integer class