May I suggest you have a look at the Java Reflection package...
java.lang.reflect
also the java.lang.Class class, class.forName() will be of interest to you.
-Original Message-
From: Michael Ni [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 02, 2003 12:24 PM
To: [EMAIL PROTECTED]
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
Hello Michael,
Wednesday, April 2, 2003, 2:24:21 PM, you wrote:
MN i will pay $2 usd if you can solve my problem. i'll send check by mail or
MN paypal.
MN my problem is i have a String variable s which stores the name of the
MN instance i want to create. how do i convert that variable to
This is a free service :) Don't think you can buy your answers here :)
Donie
-Original Message-
From: Michael Mattox [mailto:[EMAIL PROTECTED]
Sent: 02 April 2003 11:31
To: Tomcat Users List
Subject: RE: instance names problem will pay $2 for solution
When you create the instances (blue
perhaps you might benefit from exploring the 'Big Moose Saloon'
at http://www.javaranch.com. I've found it to be a great place
for folks who have java language questions.
I think it would be beneficial all around if this list could be
kept to tomcat user problems :-).
Stephen Peterson
---
Michael,
I think what you need is some reflection to sort out your problem:
String className = red;
Class c = Class.forName(className);
Object o = c.newInstance();
Red red = (Red)o;
Does this help?
Ramsay
Michael Ni wrote:
i will pay $2 usd if you can solve my problem. i'll
hi,
i think you need to use the java.lang.reflect api for this kind of stuff.
greetz
Hans
At 02:24 AM 4/2/2003 -0800, you wrote:
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
jsp:useBean id=temp scope=request class=beangame.GameInstance /
jsp:setProperty name=temp property=* /
%
String tempname = temp.getInstance_name();
beangame.Earthquake counter1 =
(beangame.Earthquake)getServletContext().getAttribute(tempname);
if (counter1 == null) {
out.println(is
problem will pay $2 for solution
jsp:useBean id=temp scope=request
class=beangame.GameInstance /
jsp:setProperty name=temp property=* /
%
String tempname = temp.getInstance_name();
beangame.Earthquake counter1 =
(beangame.Earthquake)getServletContext().getAttribute
the way i implemented
From: Barney Hamish [EMAIL PROTECTED]
Reply-To: Tomcat Users List [EMAIL PROTECTED]
To: 'Tomcat Users List' [EMAIL PROTECTED]
Subject: RE: instance names problem will pay $2 for solution
Date: Wed, 2 Apr 2003 13:24:27 +0200
Is there are reason you can't just use
10 matches
Mail list logo