30 Classes - continued

Uniform Access

  • Scala’s getters and setters use the principle of uniform access, e.g. if you change the implentation of a field declared var name to a method def name you will not need to recompile the code
  • Therefore there can’t be a variable or method (def, val or var, private or public) that has the same name in a class

Java style getters and setters

  • Scala’s automatic getters and setters are following the unoform access principle, so the getter and setter name is the same as the field it encapsulates,
  • However if you need to have Java client code accessing your Scala class, it’s as easy as adding a @BeanProperty annotation to instruct the compiler to automatically add a Java bean style getter and setter.
  • For boolean properties of style isFlag use @BooleanBeanProperty instead

See Also opens in new page

Code editor is using Scalakata.com written by Guillaume Massé