Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

kotlin

grpc

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

ApiRequest.newBuilder().build()

and

ApiRequest.getDefaultInstance()

Thanks

like image 521
Brandon Xia Avatar asked Oct 20 '25 10:10

Brandon Xia


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.

like image 72
al3c Avatar answered Oct 22 '25 02:10

al3c



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!