Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Reference in java?

Status
Not open for further replies.

entius

Instructor
Mar 20, 2001
2
ES
How i can do this?

i want to call a variable of an object:
Jlist.setListData(object.variable);
but now i want to use a reference, i try this:
SoftReference obj = new SoftReference(object);
and now i try all these options, none is util!
...JList.setListData(obj.variable);
...JList.setListData(obj.get().variable);
...Object o = obj.get();
JList.setListData(o.variable);
so i don't know how to do it!!!!
 
how about adding a method in your class to "get" the variable ? (if it's not a public variable ...)
 
Hi,

I think the problem is that the get method of SoftReference returns the referent object as an instance of java.lang.Object.
Then it will not be impossible to access to the variable public attribute since it does not exist in the Object class.
Assuming that initially you have an instance of a Foo class, and an attribute named variable, you will have to do:
...
Foo object = new Foo();//For example
...
SoftReference obj = new SoftReference(object);
...
JList.setListData(((Foo) obj.get()).variable);
...

And it will work I think.

Bye --
Globos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top