Following the JavaBean Convention
The accessors that the Scala compiler generates by default don’t conform to the JavaBean method naming conversion. This is not a big deal if your classes are used only from Scala. But, it’s rather undesirable if the classes are used from Java. That’s because, since both Java programmers and Java IDEs are so used to the JavaBean convention, the Scala style accessors would be confusing and hard to use from Java. Furthermore, most Java frameworks assume the JavaBean convention and not following that would make it hard to use Scala classes with those frameworks. No sweat—it’s an easy fix with an annotation.
Simply mark the desired field declarations with the scala.beans.BeanProperty annotation. Upon seeing this ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access