https://kotlinlang.org logo
#anko
Title
# anko
a

anthonyandroid

12/17/2016, 1:46 PM
Hi, help wanted here: I am trying to write a
doIf
extension method for my
View
. What I want is: - First check if the View is target ViewType - If so, do the things. And I try to do it, come out with these code:
Copy code
fun View.doIf(shouldDo: Boolean, init: Unit) {
    if(shouldDo) init
}
This can work but it doesn't look quite perfect... cause every time I am using this extension, I need to write the code like this:
Copy code
a.doIf(a is SomeViewType, (a as SomeViewType).doSomething)
Any idea how to auto convert
a
to
SomeViewType
? I am thinking I might have something wrong in my extension method...