# Using enums generically

**URL:** https://discuss.kotlinlang.org/t/using-enums-generically/317
**Category:** Uncategorized
**Created:** [March 5, 2015, 7:43pm UTC](https://discuss.kotlinlang.org/t/using-enums-generically/317 "2015-03-05T19:43:04Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![ajselvig](https://avatars.discourse-cdn.com/v4/letter/a/67e7ee/32.png) [@ajselvig](https://discuss.kotlinlang.org/u/ajselvig)
#### Post date: [March 5, 2015, 9:19pm UTC](https://discuss.kotlinlang.org/t/using-enums-generically/317/2 "2015-03-05T21:19:41Z")

</div>

More specifically, I _am_ able to make a generic field that uses enums, but am not able to instantiate new values. This is the core functionality I'm looking for (the abillity to persist these properties to/from JSON and a database).

```
class EnumField\<T : Enum\<T\>\>(var value : T) { &nbsp;&nbsp;fun get(thisRef: Any?, prop: PropertyMetadata): T { &nbsp;&nbsp;return value &nbsp;&nbsp;}

&nbsp;&nbsp;fun set(thisRef: Any?, prop: PropertyMetadata, newValue: T) {  
  &nbsp;&nbsp;value = newValue  
&nbsp;&nbsp;}  
&nbsp;&nbsp;  
&nbsp;&nbsp;fun fromString(raw : String) {  
&nbsp;&nbsp;value = // create a new value from raw  
  &nbsp;&nbsp;}  
}
```

So, I can’t figure out how to implement the function fromString().

---

_[View the full topic](https://discuss.kotlinlang.org/t/using-enums-generically/317)._
