Is it possible with contracts to imply the return ...
# announcements
s
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
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
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 🙂