Is it possible with contracts to imply the return type of a method to be of type T where T is a reified type parameter, so that smartcast is possible outside the method?
d
diesieben07
08/15/2021, 2:44 PM
Yes, the following works:
Copy code
inline fun <reified T> isA(value: Any?): Boolean {
contract {
returns(true) implies (value is T)
}
return value is T
}
s
Strum355
08/16/2021, 11:57 AM
Ah I forgot to mention that the value is created inside the method, not from a parameter. But I was able to work around it by rearchitecting my code a bit 🙂