This isn't an error, it was a design decision: https://en.wikipedia.org/wiki/Covariance_and_contravariance_...
You could call it bad design, but fixing it would (imo) just make Java even worse than it already is.
Man goes to doctor,
and says:
"Gee, doc, it
really hurts
when I do this."
Doctor replies:
"Then don't do that."Horrified, the second looks around and spots a civil engineer. Engineer shrugs and says, "Don't do that."
;).
There is a deeper discussion here; if you are writing good automatic tests anyway, which I hope you are, then of how much value is a rigorious type system? :)
> of how much value is a rigorous type system?
It saves a lot of time on those tests you won't have to write and maintain just to ensure that you're getting your types correct. Strong static types are also good documentation. Some type systems (e.g. Haskell) can even explicitly indicate whether a procedure is pure or has effects. Static types also enable dispatch that can be resolved at compile-time, resulting in more efficient execution. And the list goes on.
Of course, advocates of languages without static types have heard and dismissed all these arguments before. I guess it's really just a matter of taste.
For the record, I personally think a language like Typescript hit a sweet spot. Not a lot of mandatory ceremony but you have the choice to add types where it matters, e.g. at interface level. Also the duck typing saves you from inventing class names for all kind of almost-primitive types.
But the fact that the following is unsound (and has been for a while) will always remain a mystery to me:
The array type seems completely tractable and may be able to be caught by the compiler.