Singleton pattern in Java vs Kotlin

Sachin Kumar
MindOrks
Published in
1 min readJan 13, 2019

A singleton is a software design pattern that guarantees a class has one instance only and a global point of access to it is provided by that class.

In Java we create a singleton class like following:

In the above code synchronized makes sure that there will be no thread interferences when creating the instance.

But in Kotlin the equivalent of above code will be:

Yes, that’s all we need to write to create the singleton class in Kotlin :) and above singleton class can contain properties, functions and the init method.

--

--

Sachin Kumar
MindOrks

Senior Java Backend Dev | Expertise in Java Microservices, Spring Boot Framework & Android apps development.