我面临一个泛型问题:
public interface IEntity {}
public class User : IEntity {}
public class Experiments {
private IList<IEntity> list;
private IList<Action<IEntity>> actions;
public Experiments(){
list = new List<IEntity>();
actions = new List<Action<IEntity>>();
}
public void Add<T>(T entity) where T : IEntity {
list.Add(entity); // -> NO PROBLEM HERE
}
public void AddAction<T>(Action<T> handle) where T : IEntity {
actions.Add(handle); // -> HERE I GET AN ERROR
}
为什么一旦我在方法的签名上指定 T 是 IEntity,我会得到“无法从 'System.Action<T>' 转换为 'System.Action<IEntityCheck>...” ?