scala – 避免生成默认的setter getter
发布时间:2020-12-16 19:16:00 所属栏目:安全 来源:网络整理
导读:我将自己的getter和setter添加到变量中: class Person{ private var age = 0 def currentAge = age def currentAge_=(age: Int) = this.age = age } 看编译版本给出: public class Person implements scala.ScalaObject { private int age; private int ag
我将自己的getter和setter添加到变量中:
class Person{ private var age = 0 def currentAge = age def currentAge_=(age: Int) = this.age = age } 看编译版本给出: public class Person implements scala.ScalaObject { private int age; private int age(); private void age_$eq(int); public int currentAge(); public void currentAge_$eq(int); public Person(); } 我想避免自动生成默认的getter和setter.可能吗? 解决方法private[this] var age = 0 这样年龄只对实例可见. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |