brescia123
11/09/2017, 5:16 PMobject
at runtime has multiple instances?orangy
brescia123
11/09/2017, 5:20 PMorangy
brescia123
11/09/2017, 5:25 PMorangy
orangy
brescia123
11/09/2017, 5:29 PMobject
inside a when
(the object is a case of a sealed class) and the when
throws an exception (NoWhenBranchMatchedException
) because it does not find a matching case (the when
is used as an expression and I’m providing all the cases).brescia123
11/09/2017, 5:32 PMorangy
fun main(args: Array<String>) {
val y: S = S.A
val x = when (y) {
is S.A -> "1"
is S.B -> "2"
}
println(x)
}
sealed class S {
object A : S()
class B : S()
}
Is it like this? This one works fine. Anything special about your code?Andreas Sinz
11/09/2017, 5:37 PMbrescia123
11/09/2017, 5:39 PMis
on case S.A
brescia123
11/09/2017, 5:39 PMorangy
is
it works fine for me. There should be something special about your case…orangy
Paul Woitaschek
11/09/2017, 6:21 PMPaul Woitaschek
11/09/2017, 6:22 PMPaul Woitaschek
11/09/2017, 6:22 PMpaccman
11/09/2017, 6:36 PMobject
that lead to NoWhenBranchMatchedException
.
Sorry for too late response!orangy
Paul Woitaschek
11/09/2017, 7:42 PMPaul Woitaschek
11/09/2017, 7:42 PMPaul Woitaschek
11/09/2017, 7:51 PMimport com.google.common.truth.Truth.assertThat
import org.junit.Test
object MyObject
class T {
@test
fun main() {
val original = MyObject
val constructor = MyObject.javaClass.getDeclaredConstructor()
constructor.isAccessible = true
val throughReflection = constructor.newInstance()
assertThat(original).isEqualTo(throughReflection)
}
}
Paul Woitaschek
11/09/2017, 7:51 PMorangy
Paul Woitaschek
11/09/2017, 8:32 PMPaul Woitaschek
11/09/2017, 8:32 PMPaul Woitaschek
11/09/2017, 8:32 PMpaccman
11/09/2017, 8:34 PMorangy
orangy
brescia123
11/10/2017, 11:21 AMSerializable
(to be able to put it inside an Android Intent
and pass it between `Activity`s).orangy
brescia123
11/10/2017, 11:23 AMbrescia123
11/10/2017, 11:23 AMbrescia123
11/10/2017, 11:23 AMobject
as Serializable
orangy