Hi guys, I'm new into kotlin, I have a few questio...
# android
i
Hi guys, I'm new into kotlin, I have a few questions: 1. annotationProcessor or kapt? 2. Butterknife or kotlin android extensions?
d
igoticecream: Kapt? what exactly is the decision you want to make? kotlin-android-extensions or https://github.com/JakeWharton/kotterknife
i
Does kapt replace the built in annotationProcessor?
v
Yes it does, you have to use kapt with kotlin
4
Second question is a matter of taste, try android extensions and decide what you like more 😃
i
I'm already loving it 🍻
c
One downside to be careful of is views aren’t cached with android extensions. KotterKnife is still fairly useful for things like ViewHolders. I generally use a slightly customized view binder for ViewHolders and android extensions for fragments and activities.
a
Views are cached with Android Extensions - view byte code and you can see it gets compiled to a HashMap
d
They are only cached for activities and fragments iirc
a
Ah right, yea - I usually use something like
private val titleView by lazy { customViewTitle }
👌 3
i
But what have kotterknife to offer when there is butterknife? Sorry it's my first day with kotlin
b
I thought kotterknife was the same thing but with a little kotlin goodness
g
Looking at source code, kotterknife looks like a set of extension functions to simplify findViewById calls. Butterknife does so much more like resource binding, click listeners etc You can use both side by side but might not need because some things are cleaner in kotlin anyways
k
With
butterknife
you do this.
Copy code
@BindView(R.id.title) lateinit var title: TextView
and with
kotterknife
you do this.
Copy code
val title: TextView by bindView(R.id.title)
See there is less code you have to write with
kotterknife
, also you can make your views
val
where as you can't make your views final with
butterknife
.
k
@alex2069 you should avoid initializing views
by lazy
as it could cause potential memory leaks in your code. Rotating a retained fragment for instance, the lazy inited variable will be pointing to an already disposed view