Skip to content

Instantly share code, notes, and snippets.

@ATizik
Last active November 21, 2019 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ATizik/08605472c00639d771a71ca3aa202922 to your computer and use it in GitHub Desktop.
Save ATizik/08605472c00639d771a71ca3aa202922 to your computer and use it in GitHub Desktop.
Exposing superclass without backing property
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.*
interface MyViewModelInterface {
val liveData: LiveData<String>
}
class MyViewModel:ViewModel(), MyViewModelInterface {
override val liveData = MutableLiveData<String>()
}
class MyFragment:Fragment() {
val viewModel:MyViewModelInterface by viewModels<MyViewModel>()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment