4 votesAnonymous Wolf shared this idea ·
I see the point in removing the "new" constraint in favor of declaring static methods in interfaces. But as long as we have constructors the way we have them, it seems to be more consistent to have "new" constraints, and of course to extend them to typed ones.
While we're at it: I'd prefer to replace
T var = new T(args)
T var = T.Create(args)
In this form, enabling static members in interfaces would be the consistent thing to do.
And/or, we could give interfaces the ability to declare constructors.
Well, at least the editor could suggest to add this automatically every time you start to type in a member declaration.
Visual Basic modules (the equivalent of static classes) don't have this problem.
Besides, once you have an extension method in a static class, you can't make it instanciable again.
I'd like to have things like the following too:
void ExampleMethod<T, TLoadable>(XElement data)
where TLoadable : ILoadable<T>
T stuff = TLoadable.Load(data);
// do nice things with stuff