Skip to content

Cleaner object creation #64

Open
Open

Description

@pambrose

In the sample code you initialize a HelloRequest object with:

val request = HelloRequest.newBuilder().setName(name).build()

It would be a big help if you could generate a Kotlin builder for each user protobuf object:

fun helloRequest(block: HelloRequest.Builder.() -> Unit): HelloRequest =
    HelloRequest.newBuilder().let {
        block.invoke(it)
        it.build()
    }

which would allow for much cleaner object creation:

 val request = helloRequest { this.name = name }

One of your fellow Googlers uses this approach and it makes for less cluttered user code.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    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