scala: abstract classes instantiation?

后端 未结 4 539
灰色年华
灰色年华 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:02

    Scala allows you to create not only anonymous functions but anonymous classes too.

    What you have done is simular to

    class Anon extends A {
      val a = 3
    } 
    

    but without Anon name

提交回复
热议问题