title: Kotlin: Using enums with when
body: <p>Is there any way to cast a when argument to an enum?</p>
  
  <pre><code> enum class PaymentStatus(val value: Int) {
       PAID(1),
       UNPAID(2) 
   }
  
  fun f(x: Int) {
     val foo = when (x) {
       PaymentStatus.PAID -&gt; "PAID"
       PaymentStatus.UNPAID -&gt; "UNPAID"
     }
  }
  </code></pre>
  
  <p>The above example will not work, as x is int and the values provided are the enum, if I go by <code>PaymentStatus.PAID.value</code> it would work but then I don't get the benefit of when (full coverage), and </p>
  
  <pre><code>when (x as PaymentStatus)
  </code></pre>
  
  <p>does not work.</p>
  
  <p>Any one have any ideas to make this work?</p>