Skip to content

Instantly share code, notes, and snippets.

@jeffque
Created August 25, 2025 10:58
Show Gist options
  • Select an option

  • Save jeffque/eaea816ded80409951e833c4d88f9d13 to your computer and use it in GitHub Desktop.

Select an option

Save jeffque/eaea816ded80409951e833c4d88f9d13 to your computer and use it in GitHub Desktop.
Singleton, leveraging to classloader
public class MustBeSingleton {
private MustBeSingleton() {
}
public static MustBeSingleton getInstance() {
return SINGLETON_LOADER.singleton;
}
private static class SINGLETON_LOADER {
static final MustBeSingleton singleton = new MustBeSingleton();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment