Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

again and again WRAPPER

 
chintan ramavat
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried to compile it? Does it work?

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

Henry
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you can do that starting with JDK 5.0. It is called autoboxing and autounboxing.

Wrapper objects are immutable.
 
chintan ramavat
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic