Singletone in a Kotlin

Hi I have a Java code (I have zero experience in Java) which I want to rewrite in Kotlin (under a month of experience). If I’m not mistaken this is a typical singleton implementation in Java:

public class LinphoneService extends Service {
    private static LinphoneService sInstance;
    private Core mCore;

    public static LinphoneService getInstance() {
        return sInstance;
    }
    public static Core getCore() {
        return sInstance.mCore;
    }
}

Code written by myself doesn’t work so I decided to use java to kotlin converter inside Android Studio:

open class LinphoneService : Service() {
    var core: Core? = null
        // ERROR: unresolved reference for instance field
        get() = instance.field
        private set
    companion object {
        fun getCore(): Core? = instance?.core
        var instance: LinphoneService? = null
            private set
    }
    init {
        sInstance = this
    }
    mCoreListener = object : CoreListenerStub() {
            override fun onCallStateChanged(
                core: Core,
                call: Call,
                state: Call.State,
                message: String
            ) {
                if (state == Call.State.IncomingReceived) {
                    // ERROR: here I have unresolved reference core
                    val params: CallParams = Companion.core.createCallParams(call)
                } else if (state == Call.State.Connected) {
                    //
                }
            }
        }
}

Here I have two errors: unresolved reference for instance field and unresolved reference for Companion object. How can I solve this issues? Thanks.

Should I replace instance.field by instance?.core?
Should I replace Companion.core.createCallParams(call) by instance?.core?.createCallParams()?

Or something else, because this variants still don’t work for me.

I’m not much sure what is that you’re trying to do. The Java code you have is very simple and doesn’t do much.

The usual way you translate that in Kotlin is just:

object LinphoneService: Service() {
   val core = Core()  // here I assume core has a no-arg constructor, as it seems from your Java snippet.
}

that’s it, no need to touch companion objects or write methods.
You can refer to your unique instance using its name LinphoneService.

I have Interface Core does not have a constructor error

Your Java code isn’t initialising Core either (which means you’ll get null when you read it).

In any case, you should just be able to put whatever implementation you have for Code inside the LinphoneService object.
val core = /*...*/

In Java and converted Kotlin it creates core in other place with:
mCore = Factory.instance().createCore(somestring, somestring, this);
core instead of mCore for the Kotlin version