proxy

fun <T : Any> proxy(@ReferenceLiteral(mustBeInterface = true) toImplement: KClass<T>, @StringLiteral name: String? = null, handler: ProxyHandler): T(source)

Create a proxy object that implements T and responds to all method or accessor calls using handler. toImplement must be a class reference literal of an interface. The resulting object will implement toImplement.

A call to this method is transformed into an anonymous object instance by the compiler plugin. All the arguments are calculated at compilation time.

Because of this, uses of this function can potentially add a significant amount of binary size. This is based on the number of appearances of proxy() in your code, not how many times it is invoked. If you find yourself repeatedly creating proxies for the same class, consider using proxyFactory, which has a constant binary overhead per factory invocation.

Parameters

name

the name to use for the proxy class. Must be a constant value.

Throws

if it was not intrinsified by the Inspekt compiler plugin.