【问题标题】:Does the arguments in the constructor of a subclass get duplicated in parent class?子类的构造函数中的参数是否在父类中重复?
【发布时间】:2017-05-03 11:16:18
【问题描述】:

在下面的代码中:

class A(val a: Int, val b: Int)

class B(a: Int, b: Int, val c: Int) extends A(a,b)

在创建B 的实例时,变量ab 或指向它们的指针是否在内存中重复?

或者更笼统地说:B 占用的内存是否比 A + Int 的内存大小更多?

【问题讨论】:

    标签: scala memory attributes class-hierarchy


    【解决方案1】:

    看看Scala Constructor Parameters

    Do scala constructor parameters default to private val?

    B 类中的abB 的构造函数之外不可用,并且不要覆盖A 类中的任何内容

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 2013-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-28
      相关资源
      最近更新 更多