Don't forget that Strings are immutable in Java :-). You might have better luck experimenting with a JavaBean that has getters/setters for the properties you want to be able to mess with.
Craig On Wed, 1 Dec 2004 23:44:38 -0800, Dakota Jack <[EMAIL PROTECTED]> wrote: > Thanks for the response, Paul. Here's what I am up to. I can get an > object from the weak reference created from a strong reference. What > I want to do, and am not sure if I can (I am starting to think I > cannot), is to grab the object with the weak reference and make > changes which will happen also with the strong reference. So far, it > seems that when I have the object of a weak reference created form a > strong reference and change this object, it does not affect the object > of the strong reference. > > E.g. > > package com.crackwillow.deploy; > > import java.lang.ref.WeakReference; > import java.lang.ref.Reference; > > public class MyReference { > public static void main(String [] params) { > String string = new String("Aaaaaaaaaa"); > WeakReference wr = new WeakReference(string); > wr = replace(wr); > System.out.println(string); > System.out.println(wr); > string = (String)((Reference)wr).get(); > System.out.println(string); > } > > public static WeakReference replace(WeakReference wr) { > return new WeakReference(((String)wr.get()).replaceAll("A","B")); > } > } > > Apparently there is no connection between the objects referred to by > string and wr in the code shown above. > > Is this clearer? > > Jack > > > > > On Thu, 02 Dec 2004 02:03:39 -0500, Paul Speed <[EMAIL PROTECTED]> wrote: > > A WeakReference is just a way of holding a reference to an object that > > will not keep it from being garbage collected (a very useful thing). > > There are also ways that you can track when it has been garbage > > collected. Once it has been garbage collected, it's gone though. All > > you have is any data you originally associated with your WeakReference > > (by subclassing or some other method). You cannot access the referenced > > object anymore because it doesn't exist. > > > > While the object still exists (ie: is strongly referenced some where), > > you can still access it through the WeakReference. You just have to > > expect that at some point you may go to retrieve it from the > > WeakReference and get a null. > > > > Maybe it would help to know what you are trying to do with it. There > > are other Reference implementations that may be better suited. > > > > -Paul > > > > Dakota Jack wrote: > > > > > Working here on a "new" paradigm, sort of, I think. > > > > > > Apparently you can track what has happened to a strong reference with > > > a weak reference but you cannot manipulate the object referred to by > > > the strong reference by manipulating the weak reference. Is that > > > right? Seems odd to me. > > > > > > Jack > > > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > -- > > "You can't wake a person who is pretending to be asleep." > > ~Native Proverb~ > > "Each man is good in His sight. It is not necessary for eagles to be crows." > > ~Hunkesni (Sitting Bull), Hunkpapa Sioux~ > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]