Advertisement

Sri Lanka's First and Only Platform for Luxury Houses and Apartment for Sale, Rent

Monday, May 25, 2026

Writing better Singleton Pattern with Java 26 LazyConstant


Singleton is a widely used Design Pattern which guarantees a single instance of a given class is created within an application process. This is a very good design pattern for creating instances which have a very high cost for creation in terms of memory and cpu.

A typical Singleton class for a UserService will look like following;