java匿名内部类

show the code :
 
package com.test.jwen.httpApiAuto;
public class AInter {
     
     public void m0(){
          System.out.println("1");
     }
     
     public static void main(String[] args){
          new AInter().m0();
          new AInter(){
              public void m0(){
                   System.out.println("2");
              }
          }.m0();
     }
}
 
匿名内部类,就是没有名字的类,在运行的时候,会提示里面有两个类,一个AInter一个AInter$1,这个AInter$1就是这个匿名内部类
例子中重写了m0方法,一般用来简化代码编写,但个人觉得可读性降低了
 
使用前提:必须继承一个父类 或者 实现 一个接口
 
原文地址:https://www.cnblogs.com/jwentest/p/7586181.html