实现两个接口的问题。 刚刚碰到的。
现在有两个接口“说”和“写”,两个接口都定义了hello(),但却带有不相关的返回类型。接口的方法签名是String ITalk.hello(), 和void IWrite.hello()。
需要一个类既能说又能写,怎么搞啊?
现在有两个接口“说”和“写”,两个接口都定义了hello(),但却带有不相关的返回类型。接口的方法签名是String ITalk.hello(), 和void IWrite.hello()。
需要一个类既能说又能写,怎么搞啊?
我的问题是用一个类怎么实现这两个接口的功能?我也说说以前的做法吧,
已经定义了接口,使用方已经这么写了:
ITalk talker=mypackage.Factory.getTalker();
String s=talker.hello(); //说
System.out.println(s);
IWrite writer=mypackage.Factory.getWriter();
OutPutStream out=writer.hello(); //写
if(out!=null) out.write("some words here".getBytes());
以前的做法是用两个类分别实现ITalk和IWrite。