I get the following compiler warning when implementing the frameworks IComparer interface. I understand the reason why, but in my case I ensure that I initialize all values of the collection with an instance. How can I avoid the warning? I tried the bang operator but it doesn't seem to be allowed here. Maybe there is an alternative for collections which are known to have no null elements?
warning CS8767: Nullability of reference types in type of parameter 'x' of 'int FooComparer .Compare(Foo x, Foo y)' doesn't match implicitly implemented member 'int IComparer.Compare(Foo? x, Foo? y)' (possibly because of nullability attributes).
class FooComparer : IComparer<Foo>
{
public int Compare(Foo x, Foo y)
{
return y.Bar() - x.Bar();
}
}