At 11:55 PM 19/07/01, you wrote:
(And could you possibly use a more descriptive title in future? "Simple
question" could be anything, and a lot of people would delete it
immediately without reading...)
>I know this is somewhat off topic, but I have looked everywhere and can't
>find the answer to this simple question...
>
>Is there a way to test and see whether a variable has been instantiated and
>if it hasn't, instantiate it?
Object myObject;
if (myObject == null) {
myObject = new Object();
}
Tada!
>My problem is that I am working on an application that makes use of jsp's
>that are included inside many others. I want to use a bean, but if I call
>it by a different name in every spot, then they don't share information. If
>I use the same name, and the containing jsp has already declared that it is
>using the bean, then it gives me an error and says it has already been
>declared. Any ideas on how I can get around this? Thank you in advance for
>any help!!!
Ah! A different question...
Try jsp:usebean... If the bean is declared, it'll use it. If not, it'll
instantiate a new one.
If you want to know whether you've instantiated it, or if you are reusing a
previously instatiated class, it's a bit more difficult. The only way I can
think of is by setting a variable internally on instantiation and checking
that. Of course, you'd have to ensure that all the developers do the same
thing.
Jim
--
* Jim Cheesman *
Trabajo:
[EMAIL PROTECTED] - (34)(91) 724 9200 x 2360
One should
never generalize.