//其实我认为内部类主要是参数是一个接口,子类实现接口后当成参数被传入进去,我感觉安卓经常用这种方法添加监听器
//还有线程也直接new Tread(),都是这种内部类的写法
//1.下面我先写个接口
package java8.interface_new;
public interface DefaultInterface {
//接口定义需要实现方法
public int one();
public int two();
}
//2.内部类例子
import java8.interface_new.DefaultInterface;
public class TestXiushifu {
public static void main(String[] args) {
//第一种
int value = getTotal(new DefaultInterface(){
@Override
public int one() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int two() {
// TODO Auto-generated method stub
return 0;
}
});
System.out.println(value);
//第二种
int value2 = getTotal(new Outer());
System.out.println(value2);
}
/*static class Outer implements DefaultInterface{
@Override
public int one() {
// TODO Auto-generated method stub
return 1;
}
@Override
public int two() {
// TODO Auto-generated method stub
return 2;
}
}*/
public static int getTotal(DefaultInterface defaultInterface){
int totle = defaultInterface.one() + defaultInterface.two();
return totle;
}
}