I have a problem while writing some extension for ...
# announcements
w
I have a problem while writing some extension for tests. Here is the code
Copy code
kotlin
inline fun <reified T2> Any?.assertIs(message: String? = null): T2 {
    kotlin.test.assertTrue(this is T2, message)
    return this as T2;
}

inline fun <reified T1, reified T2> T1.assertIsNot(message: String? = null): T1 {
    kotlin.test.assertFalse(this is T2, message)
    return this;
}
the first one works fine
Copy code
kotlin
1.assertIs<Int>() + 2 // return 3
but the latter one does not for the lack of type inference
Copy code
kotlin
1.assertIsNot<Int, String>()  // works but have semantic problem
1.assertIsNot<String>()       // generic problem, required two generic type
1.assertIsNot<, String>()     // is it could be true for special dimond??
Is there any better choice?