Wrapper class
problem
I want some information regarding
wrapper class. If I pass Integer object to a method as an argument and
I want to change the value of that Integer object, so that it will reflect
from where it is called.
So how shall I modify it in that method so that it will reflect from where I have called. Umapada Manna. You can change the value of that
reference byreturning the reference of new Object that you have created
inmethod.
public static Integer myMethod(Integer
T)
ya, It is fine. But is there any way to change to that particular argument object T, instead creating new object and returning that one. Is wrapper class provide any method to change its content, after once created. Umapada Manna. Try this,
public static Integer myMethod(Integer T)
Pallav class TEST extends Object{
}
decode is used to Decodes a String into a Integer. so it won't work ! Umapada Manna. You can use,
Pallav I do not think it is possible to retrieve the value of S at point (1) in your program because once the function F1 is executed S loses its reference to the object pointed by X and you do not have a reference to the S object in your function Result. It could have been possible to retreive the value of S object if function F1 was'nt void. It could also have been possible to do the same if Java passed objects by reference but Java does not pass objects by reference, it passes object references by value. Vinay. You can’t do this until you return an Integer Object and collect it in calling method. Reason: All Wrapper Classes are Immutable. If you are not sure what’s exactly immutability is, then understand first. There is no setter method in any Wrapper Class. Once created can’t be changed. Sanjeev Thanks Sanjeeb. Now it is clear. Yes ! Wrapper classes are Immutable. That clear evrything to me. So only way by returning that wrapper object. Umapada Manna. Wrapper classes are immutable! That's the polished answer. Thx for that. Vinay.
Do you have a Java Problem?
Java Books
Return to : Java Programming Hints and Tips All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|