Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #36822
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2017-07-07 11:56 -0700 |
| Message-ID | <6c91c2b4-7d8f-42ba-8a51-eaef43635f49@googlegroups.com> (permalink) |
| Subject | no easy way to do a reverse pointer? |
| From | Eric Douglas <e.d.programmer@gmail.com> |
public class A {
private B fld;
public void setFld(B value) {
fld = value;
}
}
So field fld is an object, which means it's a pointer to an instance of type B, and I can have multiple instances of A referencing a single instance of B.
So the easiest way for an instance of B to tell you which instances of A hold a reference?
public class A {
private B fld;
public void setFld(B value) {
if (fld != null) {
fld.dropRef(this);
}
value.refer(this);
fld = value;
}
}
public class B {
private HashSet<A> refs = new HashSet();
public void refer(A value) {
refs.add(value);
}
public HashSet getRefs() {
return refs;
}
public void dropRef(A value) {
refs.remove(value);
}
}
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
no easy way to do a reverse pointer? Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 11:56 -0700
Re: no easy way to do a reverse pointer? Martin Gregorie <martin@address-in-sig.invalid> - 2017-07-07 19:48 +0000
Re: no easy way to do a reverse pointer? Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 13:28 -0700
Re: no easy way to do a reverse pointer? Martin Gregorie <martin@address-in-sig.invalid> - 2017-07-07 21:47 +0000
Re: no easy way to do a reverse pointer? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-07 18:06 -0400
Re: no easy way to do a reverse pointer? lewbloch@gmail.com - 2017-07-14 14:32 -0700
csiph-web