Another tour of Scala

 
 
 
 

Scala Properties

The Gist

The tour isn’t explicit about the line-savings you get via formal properties in Scala classes. Gone are the silly getters and setters.

My Interpretation

Instead of writing getName() and setName(String), Scala not only allows you to use name=, but it will also generate your accessors for you, based on your class constructor definition:

My Thoughts on this Feature

Solid gold money. Why they have yet to add this to Java is beyond me, and this is just extremely helpful. I don’t quite understand why I need _= instead of just =, but, whatever. This is a great feature. It’s even more compact than Ruby’s :attr_reader and :attr_accessor syntax.


Last Updated 08/07/2009 at 11:52:26 AM by davec

blog comments powered by Disqus