question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support extension methods on a specialized version of a raw type

See original GitHub issue

In 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:open
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
rsmckinneycommented, Mar 31, 2019

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.

0reactions
WilliamStonecommented, Mar 31, 2019

Glad to know that. Thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found