native
native copied to clipboard
☂️ Idiomatic conversions
- [ ]
T getSomeValue()that returns a private valueT someValuewith the same type and doesn't get any arguments can be converted to a Dart's getterT get someValue– potentially only under a config flag - [ ]
void setSomeValue(T t)that gets a value of typeTand returnsvoidcan be converted into a Dart's setterset someValue(T t)– potentially only under a config flag - [ ]
getmethods that only get a single argument can be converted tooperator []– potentially only under a config flag - [ ]
putmethods that only get two arguments can also be converted tooperator []=. We still probably want to generateputbecauseputusually returns the value in Java while[]=returnsvoid– potentially only under a config flag - [x]
equalsmethod can overloadoperator ==andhashCodecan override the hash code getter.
More conversions that can make the code more idiomatic to Dart? Feel free to suggest.
- Boolean getters will be often named
isField.
Overall this is similar to what most java serialization libraries do with getters / setters. (JSON, ORMs & DB drivers). They try to convert getters and setters into fields / columns.
I actually have a locally drafted proposal about better supporting such PoD (plain old data) types, but I think we are too early in the roadmap to discuss that feature.
Big +1 for doing the first two!
That would be similar to what Kotlin to Java interop does: https://kotlinlang.org/docs/java-interop.html#getters-and-setters
Big +1 for doing the first two!
That would be similar to what Kotlin to Java interop does: https://kotlinlang.org/docs/java-interop.html#getters-and-setters
Kotlin is doing some other conversions for operators as well but the documentation is somewhat vague about it: https://kotlinlang.org/docs/java-interop.html#operators
For example list[i] turns into list.get(i), and so on... (Similar to the other proposed conversions in this issue).