When you create the instances (blue, red, etc.) store them in a hashtable.

SomeObject blue = new SomeObject();
ht.put("blue", blue);

then:

public void callUse(String color) {
  SomeObject o = ht.get(color);
  o.use();
}

If your instances aren't of the same type, then define an Interface (for
example they all have a method called "use") and use that instead of
SomeObject.

> -----Original Message-----
> From: Michael Ni [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, April 02, 2003 12:24 PM
> To: [EMAIL PROTECTED]
> Subject: instance names problem will pay $2 for solution
>
>
> i will pay $2 usd if you can solve my problem.  i'll send check
> by mail or
> paypal.
>
> my problem is i have a String variable s which stores the name of the
> instance i want to create.  how do i convert that variable to
> java code so
> that i can use it in my java code.
>
> for instance
>
> this is what i want to do
>
> blue.use();
> red.use();
>
> but have somethign like
> s = "blue";
> something(s).use();
> s = "red";
> something(s).use();
>
> which does the samething as above
>
> mike
>
>
> _________________________________________________________________
> Protect your PC - get McAfee.com VirusScan Online
> http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to