Let's consider the following scenario:
  I have an abstract class, and all its subclasses will be singletons.
And I would like to have a static constructor in this abstract class,
that would instantiate the Singleton's unique instance. How can I do
that? I imagine that I should use reflection (to instantiate the
subclass, not the abstract one). 
  Following a code sample... btw, if someone's wondering why I want to
do that, I'm just curious if this can be done! I was thinking about it
yesterday :-)

public abstract class Singleton
{
  private static Singleton INSTANCE = null;
  
  static 
  {
    try
    {
      INSTANCE = (Singleton)this.getClass().newInstance();  <--- ???
    }
    catch (Exception e) {}
  }
  
  private Singleton() 
  {}
  
  public Singleton getInstance()
  {
    return INSTANCE;
  }
}

-- 

Felipe Schnack
Analista de Sistemas
[EMAIL PROTECTED]
Cel.: (51)91287530
Linux Counter #281893

Centro Universitário Ritter dos Reis
http://www.ritterdosreis.br
[EMAIL PROTECTED]
Fone/Fax.: (51)32303341


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

Reply via email to