Hi everybody, I have a question when using generic...
# announcements
w
Hi everybody, I have a question when using generics in class is there a way to get the name of the passed generic ? I mean in case I have this :
Copy code
class Test<T: C1> {
  fun getTypeName(): String {
     // Return what is T 
  }
}

fun main(args: Array<String>) {
  val t = Test<String>
  println(t.getTypeName()) // Returns String
}
g
You can probably use reified type params in an inline function, see: https://kotlinlang.org/docs/reference/inline-functions.html#reified-type-parameters
w
@greybird yes I read that but I'm not sure how I can use it in my class
a
It only works for functions so far, not classes.
c
I think reified classes are somewhere on the roadmap, at least I remember hearing something about it on this slack.