Why with function is not an Extension to Template class?

Suneet Agrawal
2 min readJun 5, 2021

After reading my last blog about Kotlin with function, a lot of developers have asked me about, why with is not an extension to Template class like other scope functions?

This post was originally posted at https://agrawalsuneet.github.io/blogs/why-with-function-is-not-an-extension-to-template-class/ and reposted on Medium on 5th June 2021.

Not only with, but run also has two implementations among which one is not an extension to Template class but a generic extension function.

The question is why?

with is an extension to generic class means it is not specific to any class. This could have been an extension to Any class which is the base class for all the classes, similar to java.lang.Object class in Java, even if you extend it or not. Or this could have been added as an extension to Template class which is compatible with Java objects also.

Please continue reading at https://agrawalsuneet.github.io/blogs/why-with-function-is-not-an-extension-to-template-class/

That’s all for now. You can read my other interesting posts here or you can enjoy my games or apps listed here. Feel free to use my open-source Android components in your app listed here. Or drop an email, if you didn’t find what you are looking for and need some help.

--

--