适配器就是将一个类适配成另一个类 示例代码:
public interface Dog { void wangwang();}public class Husky implements Dog{ @Override public void wangwang() { System.out.println("husky wangwang"); }}public interface Cat { void miaomiao();}public class LittleCat implements Cat{ public void miaomiao(){ System.out.println("miaomiao"); }}public class CatAdapter implements Dog{ private Cat cat; public CatAdapter(Cat cat) { this.cat = cat; } @Override public void wangwang() { cat.miaomiao(); }}public class Test3 { public static void main(String[] args) { Cat cat = new LittleCat(); Dog dog = new CatAdapter(cat); dog.wangwang(); }}复制代码