Help required with interface and Kotlin generics

Consider the following code:

fun main() { val myClass = MyClass () specialFunction(parameter = myClass) } interface MyInterface { fun doSomething () } class MyClass : MyInterface { override fun doSomething() { println("doSomething() function does nothing.") } } fun <MyInterface> specialFunction (parameter: MyInterface) { parameter.doSomething () } 

And I get this error message:

Kotlin: Unresolved reference: doSomething

Why isn’t it working ?

How do I implement generic based on interface / class? What I want is – only the classes that implements/inherits a specific interface/class – will be able to use the specialFunction ().

Is that even possible in Kotlin? How?

submitted by /u/SogaBan
[link] [comments]