Singleton (Java): Difference between revisions
From My Limbic Wiki
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
<syntaxhighlight lang=" | <source lang="Java"> | ||
<syntaxhighlight lang="Java" line='line'> | |||
/** | /** | ||
* Implémentation simple d'un singleton. | * Implémentation simple d'un singleton. | ||
| Line 19: | Line 20: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</source> | |||
Revision as of 03:20, 30 May 2019
<source lang="Java"> <syntaxhighlight lang="Java" line='line'> /**
* Implémentation simple d'un singleton. * L'instance est créée à l'initialisation. */
public class Singleton {
/** Constructeur privé */
private Singleton()
{}
/** Instance unique pré-initialisée */
private static Singleton INSTANCE = new Singleton();
/** Point d'accès pour l'instance unique du singleton */
public static Singleton getInstance()
{ return INSTANCE;
}
} </syntaxhighlight> </source>