且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

scala:抽象类实例化?

更新时间:2022-05-13 03:25:50

,则隐式扩展 A 。您所做的是语法糖,等效于此:

With this, you implicitly extend A. What you did is syntactic sugar, equivalent to this:

class A' extends A {
    val a = 3
}
val a = new A'

这些括号仅允许您扩展a类,创建一个新的匿名类,该类实例化值 a ,因此不再抽象。

These brackets merely let you extend a class on the fly, creating a new, anonymous class, which instantiates the value a and is therefore not abstract any more.