Let’s make our own type!
You saw how to parameterize the entire code.
Try changeMyType
fromInt
toString
.
This seem simple but it is a building block required to understand generic type later.
If you want to start now, try to replaceMyType
by the following code:
type SubType = Int type MyType = List[SubType]Do you see how you can combine types together ? Like Lego !
List
can be parameterized, we used it withInt
andString
in the past, but you can use any type you want.