Dotty is the new Scala compiler that is written in Scala 2 and it will be future Scala i.e Scala 3.0. The current version of Dotty is 0.24.0-RC1 and very soon the first stable version will be launched in the market.
Dotty is completely open source and it is available on GitHub.
With this blog, I am going to share you one of New Types that Dotty is coming up with: Intersection Type
An Intersection Type combine multiple types into one which has all the features of the individual types combined. You need to use ampersand &
operator to combine the multiple types (like A & B
).
Earlier in Scala 2, these were used as compound types A with B
. Although, you can still make use of with keyword in Dotty, but internally it is interpreted as &
and in future releases of Dotty, with
keyword will be deprecated and removed.
Intersection Types in Dotty are commutative which means that A & B
is same types as B & A
, they both will hold the same values.
You can find the complete example of Dotty Intersection Type from here.
In the example, there are two traits namely:
ResponseData
ErrorHandling
And both the traits have common method whoAmI
which is unimplemented. It means that any class who inherits these traits will have to provide the concrete implementation.
#lightbend #scala #dotty #knoldus singapore #scala3 #singapore #singaporetech