Classes That Use Generic Type Parameters, Part 1

In this free video lesson we’ll start looking at how to create Scala classes that use generic type parameters. Some of the examples include creating a Box type like this:

class Box[A](a: A)

Then using that type like this:

val s = Box("hi")
val i = Box(42)

Then we’ll create additional Scala code like this:

class Apple extends Fruit
class Banana extends Fruit
val b1 = Box[Apple](apple)
val b2 = Box[Fruit](apple)

After this, I share a second free Scala training video that shows how to use multiple generic type parameters when creating Scala classes.