Interesting. Language doesn't allow `inline + reif...
# announcements
d
Interesting. Language doesn't allow
inline + reified
in interfaces, but I still can achieve virtually the same thing with extension functions:
Copy code
interface Store {
  inline fun <reified T> getValue(key: String): T // impossible, no go

  // so doing this
  fun <T> getValue(key: String, clazz: Class<T>): T // good
}

class StoreImpl : Store {
  override fun <T> getValue(key: String, clazz: Class<T>): T {
    // code
  }
}

inline fun <reified T> Store.getValue(key: String): T {
  return this.getValue(key, T::class.java)
}

fun main(args: Array<String>) {
  val i: Int = StoreImpl().getValue("hello")
}
a
Because an extension method is different from an interface-method
g
You cannot use inline with interfaces, it doesn't make any sense. Compiler cannot inline such method, because it's part of object implementation
d
I know, I know. I just found it interesting that I can emulate the same semantics with extension methods! 🙂 From the outside it looks just like a reified method on the interface.
g
Yes, nice solution, use it too. Extension methods are really powerful