Résumé
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.
À propos de ce résultat
Cette page est générée automatiquement et peut contenir des informations qui ne sont pas correctes, complètes, à jour ou pertinentes par rapport à votre recherche. Il en va de même pour toutes les autres pages de ce site. Veillez à vérifier les informations auprès des sources officielles de l'EPFL.
Publications associées (29)
MOOCs associés (2)
Projet de programmation en java
The purpose of this MOOC is to offer a complementary capstone project to our existing MOOCs in introduction to programming. This will offer the students the possibility to both stabilize the already a
Introduction à la Programmation Orientée Objet (en Java)
Le cours suivi propose une introduction aux concepts de base de la programmation orientée objet tels que : encapsulation et abstraction, classes/objets, attributs/méthodes, héritage, polymorphisme, ..