https://kotlinlang.org logo
Title
o

o.semen

04/27/2018, 10:10 AM
Why it does not allow to assign descendant class ?
interface TopicDelegate<T: ProfileItem> {
    val title: Int
}

class DistrictDelegate(val api: INetworkApi): TopicDelegate<District> {
    override val title: Int = R.string.choose_districts
}

abstract class TopicFragment<T: ProfileItem> : BaseFragment() {
    private var modeDelegate: TopicDelegate<T> = DistrictDelegate(mNetworkApi) //does not work
    //Type mismatch. Required: TopicDelegate<T> Found: DistrictDelegate
}
d

diesieben07

04/27/2018, 10:12 AM
DistrictDelegate
is a
TopicDelegate<District>
, but a
TopicDelegate<T>
is required.
T
might not be
District
.
o

o.semen

04/27/2018, 11:43 AM
District extends ProfileItem
so
TopicDelegate<District>
should fit into
TopicDelegate<T: ProfileItem>
right ?
d

diesieben07

04/27/2018, 11:44 AM
No.
T
is a parameter, it may stand for anything that extends
ProfileItem
. So if
T
is actually a
SomeOtherProfileItem
, you can't put a
District
in there.