Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Getting the references of all the instantiated classes in my program

Reply
Thread Tools

Getting the references of all the instantiated classes in my program

 
 
D Sandher
Guest
Posts: n/a
 
      09-24-2003
Hi All,

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?

I look forward to hearing from you soon.

Thanks,
Dil


 
Reply With Quote
 
 
 
 
Michael Borgwardt
Guest
Posts: n/a
 
      09-24-2003
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};

 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      09-24-2003
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.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
Tom McGlynn
Guest
Posts: n/a
 
      09-24-2003
Michael Borgwardt <> wrote in message news:<bksf8v$5bujp$>...
> 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.

I.e., you could have code like:

[in the bidder constructor]
public Bidder(blah blah blah) {
...
collection.add(this)
...
}

Then when you want a list of all of the actors you do something
like:
actors = collection.toArray();

There are a fair number of subtleties to watch out for,
especially if you want the collection to have disparate
classes or if the code is multithreaded.

Good luck,
Tom McGlynn
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace all references to one object with references to other Jack Bates Python 3 08-06-2011 12:57 AM
web pages, instantiated classes, and parents =?Utf-8?B?cGlyaG8=?= ASP .Net 8 11-20-2006 05:25 PM
getting a null pointer, object is most definatly instantiated Justin Java 5 11-02-2006 01:12 AM
references on all Java classes within the same package Peter Parker Java 3 10-05-2006 07:00 AM
Events not firing from dynamically instantiated classes. AndrewMBaldwin@gmail.com ASP .Net 1 09-14-2005 06:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57