aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes again and again WRAPPER Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "again and again WRAPPER" Watch "again and again WRAPPER" New topic
Author

again and again WRAPPER

chintan ramavat
Ranch Hand

Joined: Sep 15, 2006
Posts: 134
Hello Ranchers !

Interger a = new Integer ("10");

a = a + 20 ; //can we do this by any means of explicit / implicit casting


if no then can i assume that we wrapping up the a = 10 as an object we are creating something similar to FINAL.


Thank you friends

Chintan Ramavat
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18855
    
  40

Have you tried to compile it? Does it work?

Hint: Make sure you try it with Java 5 or greater.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Yes you can do that starting with JDK 5.0. It is called autoboxing and autounboxing.

Wrapper objects are immutable.
chintan ramavat
Ranch Hand

Joined: Sep 15, 2006
Posts: 134
Hi Henry

no i am getting CASTING ERROR. I am running eclipse with latest JRE.
what do you think about this doubt ?

can we change Wrapper Class object or its just mean for single assignment. iam bit confused here.


Thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18855
    
  40

Originally posted by chintan ramavat:
no i am getting CASTING ERROR. I am running eclipse with latest JRE.
what do you think about this doubt ?

can we change Wrapper Class object or its just mean for single assignment. iam bit confused here.


First, confirm that you have installed and running a JRE, that is at least 5.0... Window --> Preferences --> Java --> Installed JRE --> get the path and check it.

Second, confirm that you have the compliance level set to at least Java 5.0... Window --> Preference --> Java --> Compiler --> compliant level. Also check the source and class file compatibility.


BTW, with my Java 5.0 JDK, it compiles fine. And the Integer "a" ends up with a value of 30.

Henry
[ February 20, 2007: Message edited by: Henry Wong ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: again and again WRAPPER