Why are arrays Objects, but can not be used as a base class?

Java was a compromise between non-object languages and very slow languages of that time where everything was an object (think about Smalltalk).

Even in more recent languages, having a fast structure at the language level for arrays (and usually maps) is considered a strategic goal. Most people wouldn’t like the weight of an inheritable object for arrays, and certainly nobody wanted this before JVM advances like JIT.

That’s why arrays, while being objects, weren’t designed as class instances (“An object is a class instance or an array”). There would be little benefit in having the ability to override a method on an array, and certainly not a great-enough one to counterbalance the need to check for the right method to apply (and in my opinion not a great-one enough to counterbalance the increased difficulty in code reading, similar to what happens when you override operators).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)