here's a small prototype with `j.l.r.Proxy` ``` in...
# language-proposals
k
here's a small prototype with
j.l.r.Proxy
Copy code
interface I {
    fun int(): Int
    fun double(): Double
}

object Foo : I by proxy() {
    override fun double() = 1.0
}

fun main(args: Array<String>) {
    println(<http://Foo.int|Foo.int>())
    println(Foo.double())
}

inline fun <reified T> proxy() = proxy(T::class.java)

@Suppress("UNCHECKED_CAST")
fun <T> proxy(c: Class<T>): T {
    return Proxy.newProxyInstance(c.classLoader, arrayOf(c), { _, method, _ ->
        when (method.returnType) {
            Int::class.javaPrimitiveType, Int::class.javaObjectType -> 0
            Short::class.javaPrimitiveType, Short::class.javaObjectType -> 0.toShort()
            Char::class.javaPrimitiveType, Char::class.javaObjectType -> 0.toChar()
            Long::class.javaPrimitiveType, Long::class.javaObjectType -> 0.toLong()
            Float::class.javaPrimitiveType, Float::class.javaObjectType -> 0f
            Double::class.javaPrimitiveType, Double::class.javaObjectType -> 0.0
            else -> null
        }
    }) as T
}