You can take a look at the DucKtypes project on GitHub, which allows you to use "static ducktyping". For instance:
interface Summable { fun plus() }
object x { fun plus(){ println("plus") } }
fun myFunction( s : Summable ){ s.plus() }
myFunction( x )
The project is still fairly new, but gradle -plugin may soon be launched to automate code generation.
source
share