Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Support companion object methods #14

Description

@glureau

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)
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions