public abstract class EntityBase { ... }
public interface IFoobar
{
void Foo<T>(int x)
where T : EntityBase, new();
}
public interface IFoobar<T>
where T : EntityBase, new()
{
void Foo(int x);
}
public class Foobar<T> : IFoobar, IFoobar<T>
where T : EntityBase, new()
{
public void Foo(int x) { ... }
void IFoobar.Foo<T>(int x) { Foo(x); }
}
コンパイラの警告が表示されます:Type parameter 'T' has the same name as the type parameter from outer type '...'
私はやってみました:void IFoobar.Foo<U>(int x) { Foo(x); }
しかし、UとTが同じであることを保証することはできません。Foobarクラスの実装方法は、同じであることが非常に重要です。
また、次のことも試してみました。void IFoobar.Foo<U>(int x) where U : T { Foo(x); }
ただし、UとTが等しいことを保証するものではなく、インターフェイスで定義されているため、制約を再定義することはできません。