deezer/KustomExport

Support companion object methods

Opened this issue · 0 comments

In some cases, we want to be able to provide companion object methods, for example to build the class. The class itself could have a private constructor, like in this example:

@JvmInline
internal value class DurationMs private constructor(internal val value: Long) {
    init {
        require(value >= 0)
    }

    operator fun plus(t: DurationMs): DurationMs {
        return from(value + t.value)
    }

    fun toSecond(): Int = (value / 1000).toInt()

    companion object {
        fun from(value: Long) = DurationMs(value)
    }
}