Is it possible to use reflection to get extension ...
# announcements
s
Is it possible to use reflection to get extension functions for
String
such as
toInt
toLong
etc?. I can see the file and package they are contained in here but i am not sure how to actually access them, could anyone provide a hint?
y
String::toInt
and
String::toLong
should suffice
s
yes, this would work if you know the exact type you want to cast to at compile time, how about cases when this is not known, is it possible to access
<http://String.to|String.to>*()
at runtime instead
y
Java reflection can work in this case, no? Just use
StringsKt
as the static class and get all the static functions of it, then filter them by what their second parameter is (because the first parameter will be string) and then simply just reflectively call that function
s
when i look through the functions contained in
StringsKt
the regular
toInt
or
toLong
etc functions seem non existent, seems the alternative is to use the
OrNull
version i.e
toIntOrNull
, that could definitely work for my usecase. I do still wonder why the former seems non existent