alvin's blog

How to use Scala enums (Enumeration)

Problem: You want to use an enumeration (a set of named values that act as constants) in your Scala application.


Extend the scala.Enumeration class to create your enumeration:

package {

    object Margin extends Enumeration {
        type Margin = Value
        val TOP, BOTTOM, LEFT, RIGHT = Value


Then import the enumeration to use it in your application:

How much are you worth to your employer?

A long time ago -- 1991 to be exact -- a friend of mine named Joe was a contractor for the aerospace company I worked at. Just like a consultant, Joe was paid by the hour.

At some point Joe decided he was going to leave that company to take a permanent job elsewhere, as he had a medical problem and wanted to get better insurance. Upon telling my employer of his plans, the employer came back and said, “What if we make you a full-time employee here?”

Syndicate content