<Convert a string to a any data type in kotlin> I ...
# stackoverflow
u
Convert a string to a any data type in kotlin I am trying to create a generic function to convert any string to any data type. For example convert("23") => 23 convert("2022-06-29T180200") => LocalDateTime object convert("hg") => "hg" and throw an error if not possible. This is the code used to do that without any error handling. /** * Convert a string to given class type or throw an error if it is not valid */ inline fun stringToTypeOrError(value: String): T { val v: T = when (T::class) { Int::class ->...