On Mon, 21 Jun 1999, Arjan Houtman wrote:
> Don't you get a problem here that you try to make a static reference
> to a non-static variable? 'instance' is non-static... 'getInstance'
> is static.
Yes, I believe you are correct. Doing it from memory, figured I'd
missed something :-). The correction is to make instance static (it
will be a compiler error otherwise). Also, now that I think about it,
it's probably a good idea to make getInstance synchronized.
> >public class MyGlobalVar {
> > private MyGlobalVar instance = null;
> > // whatever other member data fields needed
> >
> > private MyGlobalVar(...) {
> > // do whatever is needed to initialize MyGlobalVar
> > }
> >
> > public static MyGlobalVar getInstance() {
> > if (instance == null) instance = new MyGlobalVar(...);
> >
> > return instance;
> > }
> >
> > // whatever other memeber methods needed
> > // most likely read-only methods
> >}
> >
> >I think I got everything right there.
>
Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html