在Scala中你如何编写init函数?
发布时间:2020-12-16 18:34:01 所属栏目:安全 来源:网络整理
导读:例如,在 Ruby中我可以写 def initialize(price) @Current_price = priceend 解决方法 在scala中,您在class / trait / object body中编写所有init: class Foo(price: Int) { val currentPrice = price} 或者干脆 class Foo(val currentPrice: Int) {} 正如DN
例如,在
Ruby中我可以写
def initialize(price) @Current_price = price end 解决方法
在scala中,您在class / trait / object body中编写所有init:
class Foo(price: Int) { val currentPrice = price } 或者干脆 class Foo(val currentPrice: Int) { } 正如DNA所说,您可以将类体看作主要构造方法. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |