Extension method: Difference between revisions

Content deleted Content added
m top: added comma
m top: improved grammar
Line 5:
In [[object-oriented computer programming]], an '''extension method ''' is a [[Method (computer programming)|method]] added to an object after the original object was [[Compiler|compiled]]. The modified object is often a class, a prototype, or a type. Extension methods are features of some object-oriented programming languages. There is no syntactic difference between calling an extension method and calling a method declared in the type definition.<ref name="ms_ext">{{cite web|url=http://msdn.microsoft.com/en-us/library/bb383977.aspx|title=Extension Methods|publisher=Microsoft|accessdate=2008-11-23}}</ref>
 
Not all languages implement extension methods in an equally safe manner, however. For instance, languages such as C#, Java (via [http://manifold.systems/docs.html#the-extension-manifold Manifold], [https://projectlombok.org/features/experimental/ExtensionMethod Lombok], or [https://github.com/rogerkeays/fluent Fluent]), and Kotlin don't alter the extended class in any way, because doing so may break [[class hierarchy|class hierarchies]] and interfere with virtual method dispatching. This is whyInstead, these languages strictly implement extension methods statically and use [[static dispatch]]ing to invoke them.
 
==Support in programming languages==