title: Kotlin extension for next Enum value without reflection
body: <p>I wrote a Kotlin extension which adds <code>next()</code> for enum values. But is there an better way to do that?</p>
  
  <pre><code>fun &lt;T : Enum&lt;*&gt;&gt; T.next(): T {
      val values = this::class.java.getEnumConstants()
      return if (this.ordinal &lt; values.size - 1) 
              values[this.ordinal + 1] 
          else 
              values[0]
  }
  enum class Color {Red, Yellow, Green}
  Color.Red.next() //Yellow
  </code></pre>
  
  <ol>
  <li>Can I achieve that without reflections?</li>
  <li>If not, how to do that with Kotlins reflection?</li>
  </ol>
  
  <p>The Idea is to iterate from enum value to the next. But only for a specific value, not for whole enum <code>values()</code> list. The thing I want to prevent is to add the following to every enum type: </p>
  
  <pre><code>fun next() = if (this.ordinal == Color.values().size - 1) 
          Color.values()[0] 
      else 
          Color.values()[this.ordinal + 1]
  </code></pre>