匿名内部类

匿名内部类

通过匿名内部类实现接口方法

interface Oface{
    public void getValue();
}
public class Outer {
    public Oface doit(){
        return new Oface() {
            private int i=0;
            public void getValue(){
                 System.out.println(i);;
            }
        };
    }
    public static void main(String[] args){
        Outer ou=new Outer();
        Oface u=ou.doit();
        u.getValue();
    }
}
务实,说实话!
原文地址:https://www.cnblogs.com/xtuxiongda/p/8485716.html