title: What are sealed classes in Kotlin?
body: <p>I'm a beginner in Kotlin and recently read about <a href="https://kotlinlang.org/docs/reference/sealed-classes.html" rel="noreferrer">Sealed Classes</a>. But from the doc the only think I actually get is that they are exist.</p>
  <p>The doc stated, that they are &quot;representing restricted class hierarchies&quot;. Besides that I found a statement that they are enums with superpower. Both aspects are actually not clear.</p>
  <p>So can you help me with the following questions:</p>
  <ul>
  <li>What are sealed classes and what is the idiomatic way of using ones?</li>
  <li>Does such a concept present in other languages like Python, Groovy or C#?</li>
  </ul>
  <p><strong>UPDATE:</strong>
  I carefully checked this <a href="https://kotlinexpertise.com/kotlin-sealed-class-restricted-class-hierarchy/" rel="noreferrer">blog post</a> and still can't wrap my head around that concept. As stated in the post</p>
  <blockquote>
  <p><strong>Benefit</strong></p>
  <p>The feature allows us to define class hierarchies that are
  restricted in their types, i.e. subclasses. Since all subclasses need
  to be defined inside the file of the sealed class, there’s no chance
  of unknown subclasses which the compiler doesn’t know about.</p>
  </blockquote>
  <p>Why the compiler doesn't know about other subclasses defined in other files? Even IDE knows that. Just press <code>Ctrl+Alt+B</code> in IDEA on, for instance, <code>List&lt;&gt;</code> definition and all implementations will be shown even in other source files. If a subclass can be defined in some third-party framework, which not used in the application, why should we care about that?</p>