Eugen Martynov
08/30/2019, 1:13 PMsealed class Operation(val value: Int) { class Add()...class Divide()}
or class Operation(val type:Type, val value: Int)
where Type
is enum?Szymon Lipiński
08/30/2019, 1:16 PMEugen Martynov
08/30/2019, 1:17 PMSzymon Lipiński
08/30/2019, 1:18 PMwhen
with an object of this class, I need to check for all the subtypes or the code won't compile. It's really cool when I add a new type.Marko Mitic
08/30/2019, 1:19 PMEugen Martynov
08/30/2019, 1:21 PMSzymon Lipiński
08/30/2019, 1:22 PMsealed class
vs class
. So in this case I'd use the sealed version. There was no enum in your question 🙂Eugen Martynov
08/30/2019, 1:23 PMType
is enum in my exampleMarko Mitic
08/30/2019, 1:24 PMMarko Mitic
08/30/2019, 1:24 PMSzymon Lipiński
08/30/2019, 1:25 PMEugen Martynov
08/30/2019, 1:26 PMdata class AppErrorNetwork(
override val cause: Throwable
) : AppError()
data class AppErrorBackendRequest(
override val cause: Throwable
) : AppError()
data class AppErrorUnknown(
override val cause: Throwable,
val message: String
) : AppError()
Marko Mitic
08/30/2019, 1:26 PMinternal sealed class ProxyState {
object NoProxy : ProxyState()
sealed class Proxy(val info: ProxyInfo) : ProxyState() {
class Initializing(info: ProxyInfo) : Proxy(info)
class Active(info: ProxyInfo) : Proxy(info)
}
}
Marko Mitic
08/30/2019, 1:29 PMAppError
is sealed classEugen Martynov
08/30/2019, 1:30 PMEugen Martynov
08/30/2019, 1:31 PMMarko Mitic
08/30/2019, 1:33 PMwhen
is over switch
Marko Mitic
08/30/2019, 1:34 PMEugen Martynov
08/30/2019, 1:35 PMEugen Martynov
08/30/2019, 1:35 PMMarko Mitic
08/30/2019, 1:38 PMMarko Mitic
08/30/2019, 1:39 PMMarko Mitic
08/30/2019, 1:40 PMEugen Martynov
08/30/2019, 1:45 PMMarko Mitic
08/30/2019, 1:51 PMEugen Martynov
08/30/2019, 1:53 PMMarko Mitic
08/30/2019, 1:54 PMMarko Mitic
08/30/2019, 1:55 PMMarko Mitic
08/30/2019, 1:56 PMwhen
expressions are super simple, compiler makes sure I covered all casesMarko Mitic
08/30/2019, 1:56 PM