The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 2002



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Problems with Singletons and Static References

Posted by Tim W on February 22, 2002 at 10:47 AM

I'm trying to implement a class that uses a static method to return an instance of itself to the calling object. It's not precisely a singleton because it can also be instantiated via a call to a constructor.

I've gotten it to work more or less correctly, but I'm having trouble with methods in the instance that access non-static variables:

The pertinent code follows:

public class GeneManager {

private GeneManagerGUI gui;

private static GeneManager manager;
private static boolean initialized = false;

public GeneManager() {
this.manager = this;
initialized = true;


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us