For example
// Not valid Kotlin code.
fun <T : Summable> myFunction ...
T : Summable
means any type T
supports +
operator, i.e. has a .plus
method defined.
There is no such feature in Kotlin, and it's not planned for a future release at this time.
You may want to take a look at the DucKtypes project at GitHub, which allows for "static ducktyping". For example:
interface Summable { fun plus() }
object x { fun plus(){ println("plus") } }
fun myFunction( s : Summable ){ s.plus() }
myFunction( x )
The project is still pretty new, but might soon have a gradle-plugin to automate code-generation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With