How to get the field name of a java (weak) reference pointing to an object in an other class?
Posted
by Tom
on Stack Overflow
See other posts from Stack Overflow
or by Tom
Published on 2010-04-28T09:55:02Z
Indexed on
2010/04/28
10:03 UTC
Read the original article
Hit count: 205
Imagine I have the following situation:
Test1.java
import java.lang.ref.WeakReference;
public class Test1
{
public WeakReference fieldName;
public init()
{
fieldName = new WeakReference(this);
Test2.setWeakRef(fieldName);
}
}
Test2.java
import java.lang.ref.WeakReference;
public class Test2
{
public static setWeakRef(WeakReference weakRef)
{
//at this point I got weakRef in an other class.. now, how do I get the field name this reference was created with? So that it returns exactly "fieldName", because that's the name I gave it in Test1.java?
}
}
At the location of the comment I received the weak reference created in an other class. How would I retreive the field name that this weak reference was created with, in this case "fieldName"?
Thanks in advance.
© Stack Overflow or respective owner