0 votes
in Kotlin by
Rewrite this code in Kotlin

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;

    }

1 Answer

0 votes
by
Using Kotlin:

object Singleton

Related questions

0 votes
0 votes
asked May 26, 2022 in Kotlin by Robin
0 votes
0 votes
asked May 26, 2022 in Kotlin by Robin
...