Advertisements

Re: Getting the references of all the instantiated classes in myprogram

D Sandher wrote:
> I want to do something like the following: Say I have an Auctioneer and a
> Bidder class and then in my program I write:
>
> a1=new Auctioneer(blah blah blah);
> b1= new Bidder(blah blah blah);
> b2= new Bidder(blah blah blah);
>
> Is there a way I can get a list of references for the objects? I would
> like to have an array with a1,b1,b2 as references. Is that possible?

Advertisements

D Sandher wrote:
> I want to do something like the following: Say I have an Auctioneer and a
> Bidder class and then in my program I write:
>
> a1=new Auctioneer(blah blah blah);
> b1= new Bidder(blah blah blah);
> b2= new Bidder(blah blah blah);
>
> Is there a way I can get a list of references for the objects? I would
> like to have an array with a1,b1,b2 as references. Is that possible?

A list of all references in the application? No. You'd have to keep
track of specific references as they are created, modified, go out of
scope, etc.

Alternative, the profiling or debugging interfaces to the VM may be able
to provide this information to native code, for debugging purposes.

Michael Borgwardt <> wrote in message news:<bksf8v$5bujp$-berlin.de>...
> D Sandher wrote:
> > I want to do something like the following: Say I have an Auctioneer and a
> > Bidder class and then in my program I write:
> >
> > a1=new Auctioneer(blah blah blah);
> > b1= new Bidder(blah blah blah);
> > b2= new Bidder(blah blah blah);
> >
> > Is there a way I can get a list of references for the objects? I would
> > like to have an array with a1,b1,b2 as references. Is that possible?
>
> Sure:
> Object[] array = new Object[]{a1,b1,b2};

I'm guessing the original poster wants to be able to go somewhere and
get a list of all of the Auctioneers and Bidder's that have been created.

If that's what you want, and you never want to get rid of one of these
(or you're willing to call some special destructor method when you do),
then you can have code in the constructors for these objects save
the objects in some kind of collection.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!