【发布时间】:2010-04-28 09:55:02
【问题描述】:
假设我有以下情况:
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?
}
}
在评论的位置,我收到了在其他类中创建的弱引用。我将如何检索创建此弱引用的字段名称,在本例中为“fieldName”?
提前致谢。
【问题讨论】:
标签: java reflection reference field