Skip to content

Instantly share code, notes, and snippets.

@vibin
Created April 21, 2018 12:55
Show Gist options
  • Save vibin/cd33670cf0eb27b007c2324c3e56a8ce to your computer and use it in GitHub Desktop.
Save vibin/cd33670cf0eb27b007c2324c3e56a8ce to your computer and use it in GitHub Desktop.
import android.databinding.Observable
import android.databinding.ObservableField
class NonNullObservableField<T : Any>(
value: T, vararg dependencies: Observable
) : ObservableField<T>(*dependencies) {
init {
set(value)
}
override fun get(): T = super.get()!!
@Suppress("RedundantOverride") // Only allow non-null `value`.
override fun set(value: T) = super.set(value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment