Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add support for Kotlin #44

Open
bkrichards opened this issue Jun 20, 2018 · 0 comments
Open

[Feature] Add support for Kotlin #44

bkrichards opened this issue Jun 20, 2018 · 0 comments

Comments

@bkrichards
Copy link

bkrichards commented Jun 20, 2018

Kotlin data classes are great but default parameters quickly diminish the ability for the object to be consumed by Java in an idiomatic fashion.

data class MyObject(val name: String, val age: Int = 0)

class MyObjectBuilder() {
    private lateinit var name: String
    private var age: Int = 0

    fun withName(val name: String) = this.name = name
    fun withAge(val age: Int) = this.age = age
    fun build() = MyObject(name, age)
 }

For non-nullable fields could store them as null in the builder with added validation or just rely on lateinit validation to throw when the property is read during build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant