For instance you can implement a library providing Units of Measurements such that you can track the correct type through computations, e.g:
val time: Time[Int] = 15 s
val length: Length[Int] = 450 m
val speed: Speed[Int] = time / length
The type annotations are of course completely optional.
The interesting thing is that while the implementation is quite complex, the actual user has a very simple interface to develop against.
So while you can write complex code in Scala, Scala allows you to keep the complexity in the library-side, while it would bleed into the use-site in Java (use-site generics, anyone?).
Java can't do that. In fact, they already failed twice with it.
The interesting thing is that while the implementation is quite complex, the actual user has a very simple interface to develop against.
So while you can write complex code in Scala, Scala allows you to keep the complexity in the library-side, while it would bleed into the use-site in Java (use-site generics, anyone?).
Java can't do that. In fact, they already failed twice with it.