In terms of iOS: ``` fun checkInt(value:Int): S...
# kotlin-native
a
In terms of iOS:
Copy code
fun 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
Copy code
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?
g
For debug just try to write
else -> "Unknown ${value::class}"
a
Thanks for the trick, but seems KN compiler has a problem with the null. It says
value
has a nullable type
T
, need to make sure it is not null. Adding
!!
won’t work, same error 😄
g
But T is nullable
use
Copy code
fun <T : Any> checkGeneric(value: T):String
to make it non-nullable
a
Thanks, it works now!