Scala Sealed

A simple new keyword today

It is not possible to illustrate its main function using Scastie, so if you would like to learn more you will have to read the description snippet below. I am sorry about that.

We are reusing a lot of feature we saw in the past for this SKB. Everything should look familiar except the new keywordsealed

sealedis related to Object Oriented Programming and more specifically about inheritance.

The keywordsealedallows you to block inheritance if it is not within the same file. If you define asealedtraitorabstract class( it works for both the exact same way ), you will only be able toextendsthistraitwithin this file.

This is the reason why it is hard to illustrate it within Scastie since everything is just one worksheet.

It is very useful when you want to describe something which have finite options. We are going to learn more about a very specific use case in the next SKB.

Reveal more information and clues
Load Exercise