observeNonNull

inline fun <T : Any> LiveData<T>.observeNonNull(owner: LifecycleOwner, crossinline onChanged: (T) -> Unit): Observer<T>

Adds the given onChanged lambda as an observer within the lifespan of the given owner and returns a reference to observer. The events are dispatched on the main thread.

Copied from lifecycle-livedata-core-ktx/src/main/java/androidx/lifecycle/LiveData.kt's observe, without the method deprecation. This copy was necessary as the new Kotlin 1.4 SAM rule allows omitting the observer types, but the resulting lambda is generated from Java code which is nullable, thus not suitable for non-nullable cases. When this situation is solved, this extension can be removed. See https://android-review.googlesource.com/c/platform/frameworks/support/+/1413815/1 for more information.