How do I make method param mutable in Kotlin?

Viewed 15961

I'm implementing a SpinnerAdapter in Android project. So I have to override getView(i: Int, convertView: View, parent: ViewGroup) method. So convertView is here in order to reuse existing view and reduce memory usage and GC occurrences. So if it is null I have to create view and use already created otherwise.

So in fact I have to write something like this (officially recomended by google):

if (view == null) {
    view = View.inflate(context, R.layout.item_spinner, parent)
    view.tag(Holder(view))
} else {
    (view.tag as Holder).title.text = getItem(i)
}

But Kotlin does not allow to write to param. What I found on the internet is an official blog post that says that it is not possible since Feb, 2013.

So I'm wondering if there is any workaround ?

4 Answers
Related