编译器说得很清除啊,适配器既然实现IRoundPeg,ISquarePeg就必须实现他们的方法insertIntoHole与insert。
否则肯定不通过的啊。这个跟设计模式没有什么关系,完全是接口语法。
否则肯定不通过的啊。这个跟设计模式没有什么关系,完全是接口语法。
解决方案 »
- spring mvc的<mvc:annotation-driven/>有什么用?
- 数据库存储图片问题
- jbpm4.3/4.4如何实现国内业务
- 调用SQL进行数据转移的困惑
- 使用birt做报表必须要安装eclipse吗
- hibernate one-to-many单向问题,急啊...高手请帮帮忙
- 谁给我解释下J2EE中数据持久的含义啊?
- 想换工作了给位给点意见
- I'm a freshgirl, would you please help me about this questions?
- 请问作过EJB的高手们很简单的配置问题(使用JB)
- 各位大哥问一个问题,不知道是否很简单,但的确不是很清楚,关于try ..catch中变量返回
- 請問在java如何判斷本地目錄存不存在
SquarePeg squarePeg; PegAdapter() {
roundPeg=new RoundPeg();
squarePeg=new SquarePeg();
} PegAdapter(RoundPeg peg) {
this.roundPeg = peg;
} PegAdapter(SquarePeg peg) {
this.squarePeg = peg;
} public void sinsert(String str) {
squarePeg.insert(str);
} public void rinsert(String str) {
roundPeg.insertIntoHole(str);
} public static void main(String args[]) {
SquarePeg peg=new SquarePeg();
PegAdapter a = new PegAdapter(peg);
a.sinsert("dsfklkk"); PegAdapter b=new PegAdapter();//
b.sinsert("dsfklkk");
}
}
这样可以
SquarePeg peg=new SquarePeg();
RoundPeg reg=new RoundPeg();
PegAdapter a = new PegAdapter(peg);
a.sinsert("dsfklkk"); PegAdapter b=new PegAdapter(reg);//
b.rinsert("rsfklkk");
}
}