本文介绍了为什么是数组对象,但不能用作基类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! Java语言规范指定The Java language specification specifies that考虑数组是对象 - 为什么Java设计人员决定不允许继承和覆盖它,例如 toString() 或 equals()?So, considering arrays are objects — why did the Java designers make the decision not to allow inherit and override from it, for example, toString() or equals()?当前语法不允许创建带有数组作为基类的匿名类,但我不认为The current syntax wouldn't allow creating anonymous classes with an array as the base class, but I don't think that was the reason for their decision.推荐答案 Java是非目标语言和非常慢的语言之间的折衷方案其中一切都是一个对象(想想 Smalltalk )。Java was a compromise between non-object languages and very slow languages of that time where everything was an object (think about Smalltalk).即使在最近的语言中,在数组(通常是地图)的语言级别具有快速结构也被视为一个战略目标。大多数人不喜欢数组的可继承对象的权重,肯定没有人想要这样的JVM前进像JIT。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.这就是为什么数组作为对象时,不是设计为类实例()。jls / se8 / html / jls-4.html#jls-4.3.1有能力重写数组上的方法,并且肯定不是一个足够的一个来平衡需要检查正确的方法应用(在我看来不是一个很好的平衡代码读取的难度增加,类似于覆盖运算符时发生的情况)。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). 这篇关于为什么是数组对象,但不能用作基类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-14 06:45