我收到此错误:
“ Condition.Equals':接口无法声明类型”。
我该如何正确地做到这一点?
public interface Condition<Expected> {
public bool verify(Expected expected, object actual);
public class Equals : Condition<object> {
public bool verify(object expected, object actual) {
return expected==actual || (expected!=null && expected.Equals(actual));
}
}
答案 0 :(得分:0)
将类声明移到界面;您在界面中可以做的就是声明方法和属性:
public interface Condition<Expected> {
// you can't declare interface method as public or, say, private:
// it's the implementing class that provides the access modifier
bool verify(Expected expected, object actual);
}
public class Equals : Condition<object> {
public bool verify(object expected, object actual) {
return expected == actual || (expected != null && expected.Equals(actual));
}
}