Miguel12/24/2018, 4:14 PM
Shawn12/24/2018, 4:15 PM
Miguel12/24/2018, 4:17 PM
val x: Date = lol("13/02/2018", Date::class.java)
Shawn12/24/2018, 4:18 PM
returns a different type based on the class you pass to it, you can still use generics
, you’d get a
fun <T> lol(): T
out of it by calling like this:
from it, use
inline fun <reified T> lol()
Miguel12/24/2018, 4:21 PM
Shawn12/24/2018, 4:25 PM
, but the better question at this point really is what are you trying to do?
Miguel12/24/2018, 4:33 PM
-> Int and
-> LocalDate. Ideally I would want a function
that receives the string representation and returns the list of elements, which can be a list of 2 Ints or a list of 2 LocalDates.
fun <T> fromString(elementsString: String, classValue: Class<T>): List<T>
function to call the “parseInt” function and returning that, and only calling the “parseDate” if the other one was not well succeeded.
Shawn12/24/2018, 4:38 PM
Miguel12/24/2018, 4:41 PM
val x: List<Int> fromString("[2,2]", Int::class.java)
and I would like to delegate the responsibility of parsing to the wanted type to some other function.
Shawn12/24/2018, 5:00 PM
Miguel12/24/2018, 5:13 PM
Shawn12/24/2018, 5:14 PM
Pavlo Liapota12/25/2018, 10:13 AM
Miguel12/25/2018, 11:00 AM