Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Make sure type parameter of Event class is non-null #301

Open
wants to merge 1 commit into
base: iosched_2020
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import androidx.lifecycle.Observer
/**
* Used as a wrapper for data that is exposed via a LiveData that represents an event.
*/
open class Event<out T>(private val content: T) {
open class Event<out T : Any>(private val content: T) {

var hasBeenHandled = false
private set // Allow external read but not write
Expand Down Expand Up @@ -50,7 +50,7 @@ open class Event<out T>(private val content: T) {
*
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled.
*/
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
class EventObserver<T : Any>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
override fun onChanged(event: Event<T>?) {
event?.getContentIfNotHandled()?.let { value ->
onEventUnhandledContent(value)
Expand Down