package com.coding.base;
/**
* 匿名内部类的方法调用
*/
interface Inter {
public abstract void show1();
public abstract void show2();
}
class OuterA {
public void method(){
// 通常操作
/*
new Inter(){
public void show1(){
System.out.println("show1");
}
public void show2(){
System.out.println("show2");
}
}.show1();
new Inter(){
public void show1(){
System.out.println("show1");
}
public void show2(){
System.out.println("show2");
}
}.show2();
*/
// 优化后的操作
Inter i = new Inter() {
@Override
public void show1() {
System.out.println("show1");
}
@Override
public void show2() {
System.out.println("show2");
}
};
i.show1();
i.show2();
}
}
public class InterClass {
public static void main(String[] args){
OuterA o = new OuterA();
o.method();
}
}