william-leung
07/28/2016, 6:36 AMkotlin
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
kotlin
1.assertIs<Int>() + 2 // return 3
but the latter one does not for the lack of type inference
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?