Making the Climb Part 2–Object-Oriented Programming in Scala
In Part 2 of this series we’re going to move into some of the object-oriented aspects of Scala. For a primer on what Scala is, and a quick primer on syntax, check out part 1. Let’s start with the built-in object structure Like C# and Java, Scala has a built-in object hierarchy, and a standard library full of goodies. Unlike Java and C#, Scala tackled the issue of reference types and value types head-on, so while the root type in the Scala type system is the Any type, there are two descendants of Any that come into play before any other type. The two are: AnyRef, and AnyVal. As you might guess AnyRef is the base type for all reference types (including types made available from Java), and AnyVal is the base type for all value types. This is a little bit like the class and struct type constraints in C#, only you can use these as variables. They can also be used to limit type parameters, but Scala Generics are going to have to get their own post. ...