-
Notifications
You must be signed in to change notification settings - Fork 15.5k
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
[Kotlin] Why does the fieldOrNull extension property only support message fields? #12935
Comments
We had long internal discussions about this issue. It came down to 2 main issues:
There are still some internal discussions around this issue and we see the convenience it would add, but we would need to solve the issue on a bigger (language neutral) scale and that isn't something we are actively prioritizing now. |
Thanks for answering my question. I understand your situation. In my opinion, it would be great if you could support this feature.
In some cases, the default value was referenced without realizing it was optional, causing a bug. In the end I can't stand it and am using kapt to automatically generate the extended function.... haha. thanks. |
Thanks for the answer. I'm not too familiar with all other languages supported by Protobuf, but wouldn't this be possible to support in Java as I've also found this as a footgun, with developers expect a nullable type for optional but then unintentionally letting the default value pass through. |
Yes, I totally agree with you.
It seems that java is not supported because Optional is not available for older versions. It may be difficult due to compatibility issues, but it is not difficult to add kotlin extension functions. |
FYI: |
protobuf-kotlin introduces a useful extension property called fieldOrNull for message fields.
optional
was introduced in proto3.It would be more useful if fieldOrNull was introduced for optional fields as well. Is there any reason why this has not been introduced?
related code:
https://github.com/protocolbuffers/protobuf/blob/b30f3de12f946b6d610c21bc605726bf56ea889f/src/google/protobuf/compiler/java/message.cc#L1352C33-L1370
The text was updated successfully, but these errors were encountered: