https://kotlinlang.org logo
Title
i

igoticecream

05/18/2017, 11:49 PM
Hi guys, I'm new into kotlin, I have a few questions: 1. annotationProcessor or kapt? 2. Butterknife or kotlin android extensions?
d

drew

05/18/2017, 11:50 PM
igoticecream: Kapt? what exactly is the decision you want to make? kotlin-android-extensions or https://github.com/JakeWharton/kotterknife
i

igoticecream

05/18/2017, 11:51 PM
Does kapt replace the built in annotationProcessor?
v

vyacheslav.gerasimov

05/18/2017, 11:52 PM
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

igoticecream

05/18/2017, 11:56 PM
I'm already loving it 🍻
c

ccrowe

05/19/2017, 12:50 AM
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

alex2069

05/19/2017, 12:55 AM
Views are cached with Android Extensions - view byte code and you can see it gets compiled to a HashMap
d

drew

05/19/2017, 12:56 AM
They are only cached for activities and fragments iirc
a

alex2069

05/19/2017, 1:05 AM
Ah right, yea - I usually use something like
private val titleView by lazy { customViewTitle }
👌 3
i

igoticecream

05/19/2017, 1:56 AM
But what have kotterknife to offer when there is butterknife? Sorry it's my first day with kotlin
b

blakelee

05/19/2017, 4:38 AM
I thought kotterknife was the same thing but with a little kotlin goodness
g

gitanshu

05/19/2017, 6:13 AM
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

kalpeshp0310

05/19/2017, 6:25 AM
With
butterknife
you do this.
@BindView(R.id.title) lateinit var title: TextView
and with
kotterknife
you do this.
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

kingsley

05/19/2017, 11:36 AM
@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