mwong
06/15/2020, 11:02 AMsealed class ItemType {
data class Section(name: String) : ItemType() {
override fun areContentsTheSame(other: ItemType.Section) = name == other.name
}
data class Item(value: Long): ItemType() {
override fun areContentsTheSame(other: ItemType.Item) = value == other.value
}
abstract fun areContentsTheSame(other: ItemType): Boolean
}
Michael de Kaste
06/15/2020, 11:47 AMsealed class ItemType<T>(
val item: T
){
data class Section(val name: String) : ItemType<String>(name)
data class Item(val value: Long) : ItemType<Long>(value)
fun areContentsTheSame(other: ItemType<T>): Boolean = item == other.item
}
perhaps this is what you mean? Or at least in the right direction?Michael de Kaste
06/15/2020, 11:58 AMsealed class ItemType<T : ItemType<T>>{
data class Section(val name: String) : ItemType<Section>(){
public override fun areContentsTheSame(other: Section): Boolean = this.name == other.name
}
data class Item(val value: Long) : ItemType<Item>(){
public override fun areContentsTheSame(other: Item): Boolean = this.value == other.value
}
protected abstract fun areContentsTheSame(other: T): Boolean
}
this is probably what you wantedmwong
06/15/2020, 12:31 PMMichael de Kaste
06/15/2020, 12:32 PM