wood burning stoves*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 19651
    
  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: 19651
    
  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!

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Integer class
 
Similar Threads
Integer to double
Immutable class, choice, arraylist and vector
empty string question
Writing Integer Object to disk
Wrapper Class Object Doubt