miqbaldc
08/26/2019, 11:03 AMsource
& destination
. is it the right way to do this?
Currently, I'm checking the list of contents is DataA return ResultA
or DataB return ResultB
. But here's my actual usecase:
typealias ListMovieEntity = List<MovieEntity>
typealias ListMovieResponse = List<MovieResponse>
class MovieEntityMapper {
companion object {
fun <S : Any, D : Any> from(movies: ListMovie<S>): List<D> = movies.map {
with(it) {
when (this) {
is MovieEntity -> Movie(id)
is MovieResponse -> MovieEntity(id)
else -> TODO()
} as D
}
}
}
}
I'm doing this because, I can't do the overload on both kotlin / java due to type erasure in the runtime. e.g:
fun fun1(list: List<A>)
fun fun2(list: List<B>)
// this two function will clashes each other.
Timmy
08/26/2019, 11:38 AMSzymon Lipiński
08/26/2019, 11:38 AMdata class AList(val data: List<A>)
data class BList(val data: List<B>)
fun fun1(list: AList);
fun fun1(list: BList);
miqbaldc
08/29/2019, 4:32 AM@JvmName
.
- https://kotlinlang.slack.com/archives/C0922A726/p1566838653272100?thread_ts=1566743760.244900&cid=C0922A726
- https://kotlinlang.slack.com/archives/C4GKV43N2/p1566754221037700?thread_ts=1566743379.035500&cid=C4GKV43N2
thank you very much