I saw this on reddit. I didn’t know kotlinx synthe...
# android
h
I saw this on reddit. I didn’t know kotlinx synthetic is no longer recommended practice. Does anyone know why it is no longer recomended? https://android-review.googlesource.com/c/platform/frameworks/support/+/882241
🤔 4
👎 1
🧐 1
a
That was a selling point for jumping to Kotlin a few months ago. Is this official? FindviewById was never actually used anyway,.. usually libraries did the job
Probably it’s just a coding practice for the sample code I guess
e
Ok this is actually a relief, I was thinking I was the only one having issue with that
when i started with kotlin and synthetics I have bunch of issues with that. Problem is you can only use them AFTER
onCreateView
, and the references you get are actually nullable (escaping the type system of kotlin). This happened to me especially when you need a ref to one view in a onScrollChange-listener of some sort (that you set up in onCreateView() ). Depending on device and use case, you may have a nullpointer or not (not even deterministic 😕 )
g
you scared the shit out of me, guys) Maybe they need different requirements for their libs, but "not recommend practice" is a bit of a stretch for this PR. @Hadi Tok Why would you word your question like they officially against it? Seems like a clickbait.
P.S. never had issues with synthetics. They are awesome. Plus
LayoutContainer
👍
👍 1
h
sorry I was being sarcastic.
👍 1
s
I had issues with it too but they were minor and once you get how to work with them, It is great.
e
I don’t think they can stay as they are. Synthetic return non nullable types while actually, in some cases they are nullable.
a
Are those issues tackled with findviewbyid or butterknife, dagger etc?
I tend to use lateinit with non nullable type for view elements anyway. I’m not sure if its
the best practice, but it makes the code cleaner
d
The conversation around this PR on reddit mentioned that they don’t cache when used in viewholderes unless you do a little extra work and it’s not beginner-friendly.
a
Link to the reddit post for those who are interested: https://www.reddit.com/r/androiddev/comments/ala9p2/why_kotlinx_synthetic_is_no_longer_a_recommended/ Modularity seemed to be a big topic as well since you can’t use synthetics for view in a separate module
👍 1
j
This is just an internal note for Google’s project where they are most likely to use their own horrible stuff, like LiveData, DataBinding etc.
It doesn’t really tell the community not to use synthetics, they are pretty much beware of saying thinks like recommended practice out loud.