Is there any way to extend an object?

前端 未结 6 852
礼貌的吻别
礼貌的吻别 2020-12-05 06:29

In scala, we cannot extend object:

object X 
object Y extends X

gives an error error: not found: type X

I

6条回答
  •  天命终不由人
    2020-12-05 06:56

    If you want use methods and values from another object you can use import.

    object X{
      def x = 5
    }
    
    object Y{
      import X._
      val y = x
    }
    

提交回复
热议问题