albertgao
05/15/2018, 4:06 AMfun checkInt(value:Int): String = "number: $value"
It works. when you print(checkInt(6)) at the swift side, it will print number: 6
But this won’t work
fun <T> checkGeneric(value: T):String = when (value) {
is String -> "string"
is Int -> "number"
is Boolean -> "boolean"
else -> "Unknown"
}
String and Boolean type works fine, but print(checkGeneric(6)) will output Unknown. So, the generic is partially supported?gildor
05/15/2018, 4:59 AMelse -> "Unknown ${value::class}"albertgao
05/15/2018, 5:06 AMvalue has a nullable type T, need to make sure it is not null. Adding !! won’t work, same error 😄gildor
05/15/2018, 5:10 AMgildor
05/15/2018, 5:10 AMfun <T : Any> checkGeneric(value: T):String to make it non-nullablealbertgao
05/15/2018, 5:11 AM