I have a
sealed class MyError
. in my unit tests, I have code that checks a list of `MyError`s produced by some other source.
for some error, I'd like to assert that the error is an instance is of a specific subclass, say
MyError.Foo
data class AcceptsSpecificError {
fun check(e: MyError) {
// assert that `e` has type `MyError.Foo`
}
}
how can I do this?
I can't make this
AcceptsSpecificError<T: MyError>
because of type erasure.
also it's not feasible for
AcceptsSpecificError
to take a
val e: MyError
and then compare to that, because some of the subclasses of
MyError
are too complex to easily instantiate in a unit test environment.
EDIT: would taking a property of type
KClass<T: MyError>
work here? what I really want here is a "phantom data" kind of value I can take so that
T
is not type erased.