Found this ticket but wonder if there’s any other ...
# announcements
k
Found this ticket but wonder if there’s any other way to achieve the same result? https://youtrack.jetbrains.com/issue/KT-28298
s
is there a reason you can’t use a simple
if (obj is SomeType)
?
I’m not sure how this extension function would be used
k
This is to add smart cast support when doing assertions
If I have something like this:
Copy code
interface Foo

object Bar : Foo {
  val name: String = "bar"
}
I want to be able to safely do assertion like this:
Copy code
val foo: Foo = Bar
assertThat(foo).isInstanceOf<Bar>()
assertThat(foo.name).isEqualTo("bar")
similar to:
Copy code
if (foo is Bar) {
  assertThat(foo.name).isEqualTo("bar")
}
but with instance assertion
while taking advantage of defined contract
s
interesting… I can’t help but wonder if this is a problem with the test or method in question rather than the lack of a given assertion mechanism
are you checking for a specific implementation of something?
like the compiler should already verify a return type, unless, I guess, the return type of a given method is
T
or
Any