collections
collections copied to clipboard
Adding a ReadableCollection interface
Currently, the only interface we have is Collection, which has both getter methods and mutator methods. Because of that, its generic type is invariant.
In many cases, we might want to write code that only cares about reading from a collection, which could then benefit from having a covariant interface instead. This can be solved by adding a ReadableCollection interface as a parent of Collection, moving all reading methods to the parent interface. That parent interface would use @template-covariant
. This way, code that only cares about reading from a collection could use the ReadableCollection type, where passing a ReadableCollection<Child>
to a method expecting ReadableCollection<Parent>
would be accepted. There would be no BC break for users (the Collection interface itself would still have the same signature).
What do you think about that ? I can work on a PR if there is an interest.
I think it would be great! @template-covariant
is not inherited by extending interfaces, right?
@template
and @template-covariant
are never inherited. The child class/interface can define its own generic signature (and must use @implements
or @extends
to fulfil the parent generic signature)
Closing this as it has been implemented in #322