Avoid creating a default generator

I added my own getter and setter to the variable:

class Person{ private var age = 0 def currentAge = age def currentAge_=(age: Int) = this.age = age } 

Looking at the compiled version, you can:

 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(); } 

I want to avoid the default automatic generation and getter setter. Is it possible?

+7
source share
1 answer
 private[this] var age = 0 

so that age displayed only to the instance.

+12
source

All Articles