I’m not sure why we don’t have (as far as I’m aware) an AbstractArrayTests package that contains a full test suite you can run against an instantiated custom type that wants to be an abstract array. It could have flags for sub-interfaces, like “read-only array”.
IMO the best solution for these problems is providing a test suite for a particular interface. The implementor plugs in the type or a value, and the test suite reports detailed results or a pass/fail.
This
would not burden the language with extra syntax and complexity
allow the users who implement an interface to check the semantics, and not just a formal presence of method signatures.
Eg I can implement the array interface and include
which does IMO is not something a formal interface spec would catch. But a test suite could. Of course in due time the test suite could be enhanced by tests for errors that slip though.
I can see the value of test suites. As you say, they go beyond simply having the correct methods to ensuring that the methods are implemented in a suitable manner.
Test suites are great, just, as I was saying before, they’re a little tedious to write and require discipline to use. Ideally, I’d like to see both explicit verification of interfaces via testing and better static code analysis. But any non-trivial interface should 100% have an associated set of tests.