多个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");
    }
}

你可能感兴趣的:(java,C++,c,C#)