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


source to share





All Articles