https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
g

galex

04/12/2019, 6:22 AM
Hello, I am trying to “multiplatform” the ViewModel class from androidx:
Copy code
public abstract class ViewModel {
    protected void onCleared() {
    }
}
I hoped the following would work:
Copy code
expect abstract class ViewModel {
     protected fun onCleared()
}
And on Android declare it this way:
Copy code
actual typealias ViewModel = androidx.lifecycle.ViewModel
But because protected means different things in Kotlin and Java, I get the following error:
protected final expect fun onCleared(): Unit
is incompatible because visibility is different from
protected/*protected and package*/ open fun onCleared(): Unit
. Am I stuck here or is there a way to go around this?
y

yshrsmz

04/12/2019, 11:13 AM
r

russhwolf

04/12/2019, 11:38 AM
g

galex

04/13/2019, 5:27 AM
Thank you @yshrsmz and @russhwolf 🙂
4 Views