there's various reasons, but one that's easy to see: suppose there's a default implementation
Copy code
interface Items: Sequenceable<Item> {
fun asSequence(): Sequence<Item> = sequenceOf()
}
now
TypeOfItems.asSequence()
, if it doesn't override
asSequence()
, does not return a
Sequence<TypeOfItem>
m
Mark
04/29/2022, 2:53 AM
Ok, but what if there is not a default implementation?
e
ephemient
04/29/2022, 3:08 AM
the type checker does not know or care whether there is a default implementation or not. but even if the language did not allow for default implementations at all, you'd have to change the language definition to allow for this, and lose JVM compatibility
👍 2
m
Mark
04/29/2022, 3:34 AM
I think the error message is a bit confusing. What would “consistent values” look like, other than “the same”?
e
ephemient
04/29/2022, 3:51 AM
fair point, Kotlin does require they be the same. but I think it might allow a raw type coming via Java? not sure, haven't tested
t
Tim Oltjenbruns
04/29/2022, 12:05 PM
Can you make Items generic? The other issue that may be happening is implementing an interface twice.
Items<out T: Item> : Sequencable<T>
and then
interface TypeOfItems : Items<TypeOfItem>
If the naming
Items<Item>
at call site isn’t desirable you could typealias it