bod
04/11/2020, 4:59 PMis
returning false when it should return true 😛 I'm using a sealed class
for a state, which has a few `object`s and `data class`es as subclasses, and a when
like so:
when (state) {
is Foo -> doSomethingFoo()
is Bar -> doSomethingBar()
}
etc.
Any suggestions?bod
04/11/2020, 5:06 PMstate::class
I do get class Foo
or class Bar
Andrew
04/11/2020, 5:12 PMbod
04/11/2020, 5:14 PMbod
04/11/2020, 5:14 PMbod
04/11/2020, 5:24 PMsealed class State
object Loading:State()
object Success : State()
data class Error(val cause:String):State()
fun main(){
val state:State = Loading
logd("state=$state")
when (state) {
is Loading -> logd("Loading!")
is Success -> logd("Success!")
is Error -> logd("Error! ${state.cause}")
}
}
bod
04/11/2020, 5:25 PMAndrew
04/11/2020, 6:12 PMAndrew
04/11/2020, 6:12 PMbod
04/11/2020, 7:01 PMbod
04/11/2020, 7:01 PMbod
04/11/2020, 7:02 PMbod
04/11/2020, 7:02 PMbod
04/11/2020, 8:09 PMtypeof
and instanceof
this random StackOverflow comment seems to explain my problem:
instanceof works with objects in the same window. If you use iframe/frame or popup-windows each (i)frame/window have their own "function" object and instanceof will fail if you try to compare an object from another (i)frame/window. typeof will work in all cases since it returns the string "function".
Andrew
04/12/2020, 2:42 AMAndrew
04/12/2020, 2:44 AMbod
04/12/2020, 12:58 PMaraqnid
04/13/2020, 12:25 PMbod
04/13/2020, 12:54 PMis
work as expected in that case?