Skip to content

Instantly share code, notes, and snippets.

Created April 19, 2018 22:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
seald class sample
import org.junit.Test
sealed class Event {
class Loading : Event()
class Loaded(val result: String) : Event()
class LoadFailed(val reason: String) : Event()
class SampleTest {
fun sample() {
val event1 = Event.Loading()
val event2 = Event.Loaded("1です")
val event3 = Event.LoadFailed("やんごとなき理由です")
val events = listOf(event1, event2, event3)
events.forEach { hoge(it) }
fun hoge(event: Event) {
when (event) {
is Event.Loading -> println("読み込み中です")
is Event.Loaded -> println("こんな感じの結果です ${event.result}")
is Event.LoadFailed -> println("残念ですが失敗しました ${event.reason}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment