Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid generation of default setter getter

Tags:

scala

I added my own getter and setter to a variable:

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

Looking at compiled version gives:

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 automatic generation of default getter and setter. Is it possible?

like image 575
Konstantin Milyutin Avatar asked Jul 08 '12 22:07

Konstantin Milyutin


1 Answers

private[this] var age = 0

so that age is only visible to the instance.

like image 186
Debilski Avatar answered Nov 06 '22 09:11

Debilski