多个interface有完全相同的签名方法得情况,C#比Java得处理似乎更合理一点
Interface A:
package snippet;
public interface IAPaint {
public void paint();
}
Interface B:
package snippet;
public interface IBPaint {
public void paint();
}
这样实现就可以了:
package snippet;
public class ABImpl implements IAPaint, IBPaint {
public void paint() {
System.out.println("Paint");
}
public static void main(String[] args) {
IAPaint implA = new ABImpl();
implA.paint();
IBPaint implB = new ABImpl();
implB.paint();
}
}
实现了以后,A和B接口实现共享同个方法体。
呵呵,c#可以这样:
public class SampleClass : IControl, ISurface
{
void IControl.Paint()
{
System.Console.WriteLine("IControl.Paint");
}
void ISurface.Paint()
{
System.Console.WriteLine("ISurface.Paint");
}
}
偶尔还是会出现这样的状况得。。。
那interface的意义何在,不如直接就多继承好了。。。