How to add operator extension as a part of context of the specific class without subclassing?
<p>I'm trying to utilize operators for Wicket, which is painfully verbose.</p>

<p>My most wanted feature is to use an unary "+" to <code>add()</code> a component.
But it will be needed to work inside context of every <code>MarkupContainer</code> descendants. </p>

<p>Use should be like this:</p>

<pre><code>class SomePage() : WebPage() {
    init {
        // SomePage{} context
        +Label("someLabel","Some label") 
        // instead of this.add(Label("someLabel","Some label"))
        +object : StatelessForm&lt;Unit&gt;("someForm") {
            init {
                // StatelessForm{} context
                +Label("fieldLabel","Field label") 
                +RequiredTextField("someField")
            }
        }
    }
}
</code></pre>

<p>Is it possible to implement this now without subclassing everything? Some <em>imaginary</em> syntax of what i want:</p>

<pre><code>extend org.apache.wicket.MarkupContainer {
    operator fun&lt;T: Component&gt; T.unaryPlus():T {
        // add() is called as a method of a MarkupContainer instance
        add(this) // this@MarkupContainer.add(this@unaryPlus)
        return this
    }
}
</code></pre>

<ul>
<li><a href="https://kotlinlang.org/docs/reference/extensions.html" rel="nofollow">https://kotlinlang.org/docs/reference/extensions.html</a></li>
<li><a href="https://kotlinlang.org/docs/reference/operator-overloading.html" rel="nofollow">https://kotlinlang.org/docs/reference/operator-overloading.html</a></li>
</ul>