Why does Scala not provide any static modifier?

Scala doesn't provide any static modifier, and that has to do with the design
goal of building a pure object-oriented language where every value is an object, every
operation is a method call, and every variable is a member of some object. Having
static doesn't fit well with that goal, and along with that there are plenty of downsides to using static in the code. Instead, Scala supports something called singleton
objects.

Scala没有提供任何的static修饰符,目的是为了创建一个纯的面向对象语言,任何值都是一个对象,任何操作都是对象的方法调用,任何变量都是某个对象的成员。

但static修饰符不符合这一目的,而且在代码中不使用static已是大势所趋。Scala使用单例object来代替static.

虽然,这样说了,我还不是很明白。我从《面向对象分析与设计》中看到“面向对象编程”的定义:

面向对象编程是一种实现方法,在这种方法中,程序被组织成许多相互协作的对象,每个对象代表某个类的一个实例,而类则属于一个通过继承关系形成的层次结构

这样说来,我倒觉得“任何操作都是对象的方法调用”这点不是面向对象编程的必要条件。所以,拿这点来说不支持static,似乎有些牵强。

你可能感兴趣的:(jvm,scala)