miqbaldc
08/25/2019, 2:30 PMfun fun1(list: List<DataA>)
fun fun1(list: List<DataB>)
The current condition declaration was clashed. any workaround?
1. I've tried to use typealiases
but it still clashed. e.g: typealias ListDataA = List<DataA>
2. Using extensions function, still clashed. e.g: ListDataA.fun1()Szymon Lipiński
08/25/2019, 2:41 PM@JvmName("fun1DataA")
fun fun1(list: List<DataA>)
fun fun1(list: List<DataB>)
Jack Englund
08/26/2019, 12:12 AMfun fun1(list: List<Any>)
and then check if the list's contents are DataA
or DataB
. That way you have one function.miqbaldc
08/26/2019, 10:58 AMDataA
or DataB
. 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
}
}
}
}
actually I've two generic class. source & destination. is it the right way to do this?