Is there a difference between .getDefaultInstance() and .newBuilder().build()?

Viewed 640

Doing this in Kotlin with gRPC API. Is there a difference between these two?

ApiRequest.newBuilder().build()

and

ApiRequest.getDefaultInstance()

Thanks

1 Answers

From https://developers.google.com/protocol-buffers/docs/reference/java-generated

static Foo getDefaultInstance(): Returns the singleton instance of Foo. This instance's contents are identical to what you'd get if you called Foo.newBuilder().build() (so all singular fields are unset and all repeated fields are empty). Note that the default instance of a message can be used as a factory by calling its newBuilderForType() method.

Related