zl程序教程

您现在的位置是:首页 >  后端

当前栏目

高阶函数与接口混入和java匿名类

JAVA接口 函数 匿名 高阶
2023-09-11 14:18:45 时间

高阶函数与接口混入和java匿名类。

高阶函数中的组件(参量)函数相当于面向对象中的混入(接口)类。

 

public abstract class Bird {
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public abstract int fly();
}

 

public static void main(String[] args) {
Test test = new Test();
test.test(new Bird() {

public int fly() {
return 10000;
}

public String getName() {
return "大雁";
}
});
}