Singleton Wizard

Lire cette page en français Go back

This wizard will generate a basic singleton class.

A singleton is an object that has zero or one instance maximum. It can be accessed by its ClassName.getInstance() method.
Example of a singleton class file:
import java.io.*;
import java.util.*;

public final class Preference {

  /** This is the default instance used for this singleton. */
  private static Preference defaultInstance;

  /**
   * Constructor of the object. <br>
   *
   * This constructor should remain private
   */
  private Preference() {
    super();
    // Put your code here
  }

  /**
   * Gets the unique instance of this class. <br>
   *
   * @return the unique instance of this class
   */
  public final synchronized static Preference getInstance() {
    if (Preference.defaultInstance == null) {
      Preference.defaultInstance = new Preference();
    }
    return Preference.defaultInstance;
  }
}
  

Notes :

Comments, ideas and bugs mail me at : Contact