Is it safe to remove a generic constraint?

interface IFoo<in T> where T : Bar {
    Do(T bar);
}

      

Is it possible to break anything by removing the constraint on T

?

I don't think you can abort any implementation IFoo

, because they either implement it with a specific type MyFoo : IFoo<MyBar>

, or they declare the same / stronger constraint when the implementation itself is MyFoo<T> : IFoo<T> where T : MyBar

.

I also don't think you can break any use of the interface, because again such a method either passes a specific type foo.Do(new MyBar)

or declares the same / stronger constraint UseFoo<T>(...) where T : MyBar

.

Am I missing a situation where even double backward incompatibility can occur?

+3
generics c # backwards-compatibility


source to share


No one has answered this question yet

Check out similar questions:

1758
How do I generate a random int?
1152
Type Check: typeof, GetType or is there?
1106
Create a generic method limiting T to Enum
1027
How do I create a generic array in Java?
868
How do I use reflection to call a generic method?
650
How to get an instance of a generics class of type T
636
How do I get the type T from a member of a generic class or method?
547
Create an instance of a generic type in Java?
315
Is there a limitation that restricts my generic method to numeric types?
245
C # syntax syntax for multiple type parameter constraints



All Articles
Loading...
X
Show
Funny
Dev
Pics