SingletonHolder

open class SingletonHolder<out T, in A>(val creator: A.() -> T)(source)

Use SingletonHolder to build a singleton with parameters.

class Singleton private constructor(name: String) {

... // do other things.

companion object:SingletonHolder<Singleton,String>(::Singleton)

}

// Get the singleton.
private val singleton by lazy {
Singleton.getInstance(defaultLogTag())
}

Since

0.0.3

Parameters

T

the singleton class.

A

the parameters class.

Constructors

Link copied to clipboard
constructor(creator: A.() -> T)

Properties

Link copied to clipboard
private val creator: A.() -> T

the constructor of the T.

Link copied to clipboard
private var instance: T?

Functions

Link copied to clipboard
fun getInstance(arg: A): T