This is part 3 in a series. If you’ve not followed-along so far, you may want to check out Part 1 and Part 2 first.
It’s time to start digging in to some of the crazy-goodness that makes Scala such a glorious and wonderful thing. First things first, though, we have to talk a little bit about this history of Generics in Java and the JVM. Type Erasure and you… Back around the time that .Net was adding support for generics, the folks in Java land were doing the same…sort of. The biggest difference between the way Generics were implemented in .Net and Java is the fact that in .Net generics are supported directly in the CLR (sometimes called reified generics), whereas the JVM did not include direct support for generics. Ok, so what does that actually mean? Well, for starters it means that when you’re dealing with Generics in Java you run into Type Erasure. Type Erasure means that when Java code with generics are compiled, the generic type information is removed at compile time, so while you’re looking at an ArrayList in Java, the JVM sees this as just an ArrayList, and things get cast as needed. There are a couple of types which get reified into actual types (Arrays are the best example), but for the most part this doesn’t happen. In contrast in the .Net world a List gets compiled into a List`1<System.String> which is a real type at the IL level. Now, I’m not going to get into the argument about whether or not type erasure is good or bad, but it is a fundamental difference between the two platforms. ...