title: Why can I not call .values() on generic enum class?
body: <p>I know that calling .values() on an enum class gives an array of the enum cases. However it doesn't work with a generic enum class. Why is this, and what can I do to get the same functionality?</p>
  
  <pre><code>class EnumEditActivity&lt;E: Enum&lt;E&gt;&gt;() {    
      var value: E? = null
      var allValues: Array&lt;E&gt; = E.values()
  }
  </code></pre>
  
  <p>If I call values() on a normal enum, it works fine:</p>
  
  <pre><code>enum class Gender {
      male, female
  }
  
  for (value in Gender.values()) {
      println(value.name)
  }
  </code></pre>
  
  <p>prints:</p>
  
  <pre><code>male
  female
  </code></pre>
  
  <p>Some answers suggest doing something like this:</p>
  
  <pre><code>enum class SomeEnum {
      one, two
  }
  
  class EnumEditActivity&lt;E: SomeEnum&gt;() {    
      var value: E? = null
      val values = listCases&lt;SomeEnum&gt;()
  
      inline fun &lt;reified E: SomeEnum&gt; listCases() = (E::class.java).enumConstants.toList()
  }
  </code></pre>
  
  <p>This doesn't work because it's not dynamic: it will always just get the cases for SomeEnum, so there's no point having a generic class. You can't pass any other enum apart from SomeEnum into the class, because one enum cannot inherit from another.</p>
  
  <p>I don't think this is possible in Kotlin. I'm now just defining the class so it requires you to pass in an array of the enum's cases in the class initializer:</p>
  
  <pre><code>class EnumEditActivity&lt;E&gt;(val values: Array&lt;E&gt;)
  </code></pre>