Bart
11/03/2020, 7:35 AM/**
* Asserts that two objects of type [T] are equal.
*/
infix fun <T> T.shouldBe(that: T) {
Assertions.assertEquals(that, this)
}
So that I can easily write data.property shouldBe value
, this works great.
But when I supply two values of different types "string" shouldBe 5
, the compiler doesn't complain. It infers the generic type to be Any
.
While valid behaviour, it's not what I want to happen. Is there a way I can tell Kotlin to not upcast the generic type if the argument type is not assignable to the receiver type?Fleshgrinder
11/03/2020, 9:11 AM<A : B, B : A>
Chantry Cargill
11/03/2020, 9:21 AMakatkov
11/03/2020, 4:10 PMakatkov
11/03/2020, 4:10 PM