scala: abstract classes instantiation?

后端 未结 4 540
灰色年华
灰色年华 2021-02-04 15:46

How it comes that I instantiate an abstract class?

  abstract class A {
    val a: Int
  }

  val a = new A {val a = 3}

Or is some concrete cla

4条回答
  •  盖世英雄少女心
    2021-02-04 16:00

    you're instantiating an anonymous class that inherits from A and overloads its abstract a member. For reference, see the part about anonymous class instantiations in A Tour of Scala: Abstract Types

提交回复
热议问题