Rewrite this code in Kotlin

Technology CommunityCategory: KotlinRewrite this code in Kotlin
VietMX Staff asked 3 years ago
Problem

Can you rewrite this Java code in Kotlin?

public class Singleton {
    private static Singleton instance = null;
    private Singleton(){
    }
    private synchronized static void createInstance() {
        if (instance == null) {
            instance = new Singleton();
        }
    }
    public static Singleton getInstance() {
        if (instance == null) createInstance();
        return instance;
    }

Using Kotlin:

object Singleton