Why with function is not an Extension to Template class?
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.