title: How to obtain all subclasses of a given sealed class?
body: <p>Recently we upgraded one of our enum class to sealed class <strong>with objects as sub-classes</strong> so we can make another tier of abstraction to simplify code. However we can no longer get all possible subclasses through <code>Enum.values()</code> function, which is bad because we heavily rely on that functionality. Is there a way to retrieve such information with reflection or any other tool?</p>
  
  <p>PS: Adding them to a array manually is <em>unacceptable</em>. There are currently 45 of them, and there are plans to add more.  </p>
  
  <hr>
  
  <p>This is how our sealed class looks like:</p>
  
  <pre><code>sealed class State
  
  object StateA: State()
  object StateB: State()
  object StateC: State()
  ....// 42 more
  </code></pre>
  
  <p>If there is an values collection, it will be in this shape:</p>
  
  <pre><code>val VALUES = setOf(StateA, StateB, StateC, StateC, StateD, StateE,
      StateF, StateG, StateH, StateI, StateJ, StateK, StateL, ......
  </code></pre>
  
  <p>Naturally no one wants to maintain such a monster.</p>