Fields which satisfy JavaBean specification – BeanProperties in Scala

We have seen previously about declaring fields in classes in Scala and also saw the kind of bytecode created for each of the cases. But lot of Java tools out there expect the fields in classes to follow the JavaBeans specification and in order to support that Scala provides @BeanProperty annotation.

The field which was declared with var keyword would have a getField and setField generated where as the field declared with val keyword would have only a getField generated. We already know from here the difference between val and var.

In the above example, title is declared as var and isbn is declared as val. Hence there are getters and setters assocaited with title field and only getter associated with the isbn field.