3 ms·
Generics in C# and generics in Scala have the same basic features (generic classes/interfaces/methods). When I say "powerful", the first thing that comes to min
by joslin01 11y ago
Generics in C# and generics in Scala have the same basic features (generic classes/interfaces/methods). When I say "powerful", the first thing that comes to mind is its ongoing reflection evolution. TypeTags give us access to class information in a functional manner (by passing in an implicit type info object) that we can take advantage of using Scala's (also powerful) matching mechanism.
The second thing that comes to mind is the ability to support variance. To quote Twitter Scala School: "A central question that comes up when mixing OO with polymorphism is: if T’ is a subclass of T, is Container[T’] considered a subclass of Container[T]?" Scala allows us to express this information using +/- as in `Container[+D]` allows for subclasses of `D`.
Finally, though not so much related, an interesting development in the type space is type macros (http://docs.scala-lang.org/overviews/macros/typemacros.html http://docs.scala-lang.org/overviews/macros/typemacros.html). This will give us a stronger "generic" approach to programming that allows us to write code to construct type hierarchies. In general, Scala is moving fast and always evolving.
You'd have to be more specific as to what your problems are concerning boxing & jvm. Lists are properly specialized such that a = List(1) == List<Int> and a(0) == Int. Of course, if you use a diverse set of types in the list, you'll have a `List<Any>` which then you would use `match` like so...
match item {
case i:Int => println("int " + i)
case s:String => println("string " + s)
}