brescia123
11/09/2017, 5:16 PMobject
at runtime has multiple instances?orangy
11/09/2017, 5:17 PMbrescia123
11/09/2017, 5:20 PMorangy
11/09/2017, 5:25 PMbrescia123
11/09/2017, 5:25 PMorangy
11/09/2017, 5:27 PMbrescia123
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).orangy
11/09/2017, 5:36 PMfun 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
orangy
11/09/2017, 5:40 PMis
it works fine for me. There should be something special about your case…Paul Woitaschek
11/09/2017, 6:21 PMpaccman
11/09/2017, 6:36 PMobject
that lead to NoWhenBranchMatchedException
.
Sorry for too late response!orangy
11/09/2017, 7:33 PMPaul Woitaschek
11/09/2017, 7:42 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)
}
}
orangy
11/09/2017, 7:57 PMPaul Woitaschek
11/09/2017, 8:32 PMpaccman
11/09/2017, 8:34 PMorangy
11/09/2017, 9:40 PMbrescia123
11/10/2017, 11:21 AMSerializable
(to be able to put it inside an Android Intent
and pass it between `Activity`s).orangy
11/10/2017, 11:22 AMbrescia123
11/10/2017, 11:23 AMobject
as Serializable
orangy
11/10/2017, 12:25 PM