java.util.Map接口,通过内部接口实现。
例子:
interface xx{
...
interface yy{
...
}
}
例子:
/**
* 接口与内部接口 工厂方法
*
* @author xiaofeng.zhouxf
*/
interface InnerOne {
Print getPrint();
interface Print {
void printOut();
}
}
----------------------------------------------------
/**
* 内部类 实现内部接口
*
* @author xiaofeng.zhouxf
*/
public class InnerOneImpl implements InnerOne {
public static InnerOneImpl one;
public static InnerOneImpl getInstance() {
if (one == null) one = new InnerOneImpl();
return one;
}
public Print getPrint() {
return new Print();
}
class Print implements InnerOne.Print {
public void printOut() {
System.out.println("innerOne............");
}
}
}
-------------------------------------------------
/**
* 匿名内部类 实现内部接口
*
* @author xiaofeng.zhouxf
*/
public class InnerOneImpl2 implements InnerOne {
public static InnerOneImpl2 one;
public static InnerOneImpl2 getInstance() {
if (one == null) one = new InnerOneImpl2();
return one;
}
public Print getPrint() {
// TODO Auto-generated method stub
return new Print() {// 实现了Print内部接口的匿名内部类
public void printOut() {
// TODO Auto-generated method stub
System.out.println("innerTwo............");
}
};
}
}
-----------------------------------------------------
public class InnerMainTest {
public static void main(String... strings) {
InnerOne one = InnerOneImpl.getInstance();
InnerOne one2 = InnerOneImpl2.getInstance();
one.getPrint().printOut();
one2.getPrint().printOut();
}
}
----------------------------------------------------
打印结果:
innerOne............
innerTwo............