Miguel
12/24/2018, 4:14 PMShawn
12/24/2018, 4:15 PMList<Any>
Miguel
12/24/2018, 4:17 PMval x: Date = lol("13/02/2018", Date::class.java)
🤔Shawn
12/24/2018, 4:18 PMlol()
returns a different type based on the class you pass to it, you can still use genericsfun <T> lol(): T
, you’d get a Date
out of it by calling like this: lol<Date>()
Class<T>
from it, use reified
inline fun <reified T> lol()
Miguel
12/24/2018, 4:21 PMShawn
12/24/2018, 4:25 PMinline
, but the better question at this point really is what are you trying to do?Miguel
12/24/2018, 4:33 PM(2, 2)
-> Int and (27/03/2017, 28/03/2017)
-> LocalDate.
Ideally I would want a function fun <T> fromString(elementsString: String, classValue: Class<T>): List<T>
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.fromString
function to call the “parseInt” function and returning that, and only calling the “parseDate” if the other one was not well succeeded.Shawn
12/24/2018, 4:38 PMMiguel
12/24/2018, 4:41 PMval x: List<Int> fromString("[2,2]", Int::class.java)
fromString
and I would like to delegate the responsibility of parsing to the wanted type to some other function.Shawn
12/24/2018, 5:00 PMMiguel
12/24/2018, 5:13 PMShawn
12/24/2018, 5:14 PMPavlo Liapota
12/25/2018, 10:13 AMMiguel
12/25/2018, 11:00 AM