Summary
In object-oriented computer programming, an extension method is a method added to an object after the original object was 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. Not all languages implement extension methods in an equally safe manner, however. For instance, languages such as C#, Java (via Manifold, Lombok, or Fluent), and Kotlin don't alter the extended class in any way, because doing so may break class hierarchies and interfere with virtual method dispatching. This is why these languages strictly implement extension methods statically and use static dispatching to invoke them. Extension methods are features of numerous languages including C#, Java via Manifold or Lombok or Fluent, Gosu, JavaScript, Oxygene, Ruby, Smalltalk, Kotlin, Dart, Visual Basic.NET and Xojo. In dynamic languages like Python, the concept of an extension method is unnecessary because non-builtin classes can be extended without any special syntax (an approach known as "monkey-patching", employed in libraries such as gevent). In VB.NET and Oxygene, they are recognized by the presence of the "extension" keyword or attribute. In Xojo the "Extends" keyword is used with global methods. In C# they're implemented as static methods in static classes, with the first argument being of extended class and preceded by "this" keyword. In Java you add extension methods via Manifold, a jar file you add to your project's classpath. Similar to C# a Java extension method is declared static in an @Extension class where the first argument has the same type as the extended class and is annotated with @This. Alternatively, the Fluent plugin allows you to call any static method as an extension method without using annotations, as long as the method signature matches.
About this result
This page is automatically generated and may contain information that is not correct, complete, up-to-date, or relevant to your search query. The same applies to every other page on this website. Please make sure to verify the information with EPFL's official sources.