https://kotlinlang.org logo
#android
Title
# android
h

Hadi Tok

01/30/2019, 8:12 AM
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

antonis

01/30/2019, 8:28 AM
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

Ema

01/30/2019, 8:43 AM
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

ghedeon

01/30/2019, 8:50 AM
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

Hadi Tok

01/30/2019, 8:54 AM
sorry I was being sarcastic.
👍 1
s

Saiedmomen

01/30/2019, 8:55 AM
I had issues with it too but they were minor and once you get how to work with them, It is great.
e

Ema

01/30/2019, 9:04 AM
I don’t think they can stay as they are. Synthetic return non nullable types while actually, in some cases they are nullable.
a

antonis

01/30/2019, 9:15 AM
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

dknapp

01/30/2019, 2:30 PM
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

Allan Wang

01/30/2019, 5:33 PM
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

Jirka

01/31/2019, 12:17 AM
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.