# Reified type parameters for inline classes

**URL:** <https://discuss.kotlinlang.org/t/reified-type-parameters-for-inline-classes/18253>\
**Category:** Language Design\
**Created:** [June 27, 2020, 4:56pm UTC](https://discuss.kotlinlang.org/t/reified-type-parameters-for-inline-classes/18253 "2020-06-27T16:56:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterhenryd](https://avatars.discourse-cdn.com/v4/letter/p/90db22/32.png) [@peterhenryd](https://discuss.kotlinlang.org/u/peterhenryd)\
**Post date:** [June 27, 2020, 4:56pm UTC](https://discuss.kotlinlang.org/t/reified-type-parameters-for-inline-classes/18253/1 "2020-06-27T16:56:39Z")

</div>

As far as I know, this should be possible.

```auto
inline class Blah<reified T>(val name: String) {
     fun bloh(): String {
          return "${T::class.simpleName}: $name"
     }
}

```

I’m not sure how much needs to be explained, it’d work similar to reified type parameters in inline functions.

This is currently not possible but it’d make sense to implement it as a feature.

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [June 27, 2020, 5:26pm UTC](https://discuss.kotlinlang.org/t/reified-type-parameters-for-inline-classes/18253/2 "2020-06-27T17:26:30Z")

</div>

This is not possible to to the type errasure of the JVM. Currently inline classes can’t be inlined in all cases (generics is the one example I can think of right now). This means that there is no way for an inline class to have access to a reified type, since that relies on inlining.

---

<div class="post-metadata">

**Author:** ![fvasco](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fvasco/32/1961_2.png) [@fvasco](https://discuss.kotlinlang.org/u/fvasco)\
**Post date:** [June 27, 2020, 5:26pm UTC](https://discuss.kotlinlang.org/t/reified-type-parameters-for-inline-classes/18253/3 "2020-06-27T17:26:50Z")

</div>

Take a look here [Typeclass KClass](https://discuss.kotlinlang.org/t/typeclass-kclass/6760)

---

<div class="post-metadata">

**Author:** ![fatjoe79](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fatjoe79/32/4221_2.png) [@fatjoe79](https://discuss.kotlinlang.org/u/fatjoe79)\
**Post date:** [June 30, 2020, 5:44am UTC](https://discuss.kotlinlang.org/t/reified-type-parameters-for-inline-classes/18253/4 "2020-06-30T05:44:21Z")

</div>

While this is not supported by Kotlin in this form, you can still simulate it without sacrificing the convenient API of your class this way:

```
fun main() {
    println(Blah<Int>("foo").bloh()) 
    // prints Int: foo
}
    
    
class Blah<T : Any>(val name: String, val clazz: kotlin.reflect.KClass<T>) {
     fun bloh(): String {
          return "${clazz.simpleName}: $name"
     }

     companion object {
          inline operator fun <reified T : Any> invoke(name: String) = Blah(
              name, T::class
          )
     }
}

```

---

<div class="post-metadata">

**Author:** ![peterhenryd](https://avatars.discourse-cdn.com/v4/letter/p/90db22/32.png) [@peterhenryd](https://discuss.kotlinlang.org/u/peterhenryd)\
**Post date:** [July 7, 2020, 12:02am UTC](https://discuss.kotlinlang.org/t/reified-type-parameters-for-inline-classes/18253/5 "2020-07-07T00:02:43Z")

</div>

Wow, that’s a really interesting approach! I’ll definitely take advantage of that.
