What Scala adds to Java is a stronger type system, including generics that can span several levels, which means that you can have a generic of generics, and so on.
We won't cover the Scala type system here as it would take the rest of the book to get the gist of it, but we'll take an overview of what is often needed in templates when declaring the arguments they can take.
The two major differences between the Java syntax and the Scala syntax are as follows:
Scala declares generics between square brackets (
[
...]
) whereas Java does it between angle ones (<
...>
).Java allows the declaration of a generic extending another type using the
extends
keyword (Juice[F extends Fruit]
). Scala generics can be lower and upper bounded using operators>:
and<:
, so where Java generics are only able to declare upper bounds, Scala can declare lower constraints as well.