Support extension methods on a specialized version of a raw type
See original GitHub issueIn addition to generic types, also support extension methods on specific parameterized instances of generic types. For example:
package extensions.java.util.List;
import manifold.ext.api.Extension;
import manifold.ext.api.This;
import java.util.List;
@Extension
public class MyListOfStringExt {
public static String foo(@This List<String> thiz) {
return thiz.get( 0 );
}
}
The idea is the type variables are inferred from the @This parameter type and, thus, only apply accordingly. An alternative format follows more closely with a normal extension method on a generic class, which specifies the type var. This one has the advantage of supporting covariance:
public static <E extends String> String foo(@This List<E> thiz) {
return thiz.get( 0 );
}
Should be straightforward to implement in Manifold. The challenge is probably more with Intellij to get code completion to filter out such extension methods when they don’t apply.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Extension Methods - C# Programming Guide - Microsoft Learn
Extension methods in C# enable you to add methods to existing types without creating a new derived type, recompiling, or otherwise modifying ...
Read more >Extension methods must be defined in a non-generic static class
Every extension method must be a static method; The first parameter of the extension method should use the this keyword. Share.
Read more >Using Generic Extension Methods - CodeProject
Extension Methods is a new feature in C# 3.0 and the Common Language Runtime, which allows existing classes to use extra methods (extension ......
Read more >Extension methods in C# 3.0 - Info Support Blog
Extension methods are new to C# 3.0 and enable you to extend existing types with new Methods. It's used for the new Query...
Read more >C# Extension Method - TutorialsTeacher
An extension method is actually a special kind of static method defined in a static class. To define an extension method, first of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Right… if you want contravariance on the return type, you’ll have to use a non-extension method for that. This is a case that will be supported when this issue (#7) is implemented.
Glad to know that. Thanks!