Java通過接口實現(xiàn)匿名類的實例代碼
package com.chase.test;
/**
* 通過接口實現(xiàn)匿名類的實例
*
* @author Chase
*
* @date 2013-10-18 下午04:28:17
*
* @version V1.0
*/
interface I1 {
void print();
void eat();
}
public class AnonymousClass {
public static String excute(I1 c){
System.err.println("excute方法打印...");
c.print();
c.eat();
return "excute()返回的值...";
}
public String testExcute() {
return excute(new I1(){
public void print() {
System.out.println("調(diào)用匿名內(nèi)打印...");
}
public void eat() {
System.out.println("今天的飯菜好好吃...");
}
}) ;
}
public static void main(String[] args) {
AnonymousClass entity = new AnonymousClass();
System.out.println(entity.testExcute());
}
}
運行結(jié)果:
相關(guān)文章
關(guān)于springboot中nacos動態(tài)路由的配置
這篇文章主要介紹了springboot中nacos動態(tài)路由的配置方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-09-09Idea為java程序添加啟動參數(shù)(含:VM?options、Program?arguments、Environme
設(shè)置啟動參數(shù)的意義就是當(dāng)啟動程序時,程序會優(yōu)先讀取idea的配置參數(shù),這樣就可以不用修改配置文件,下面這篇文章主要給大家介紹了關(guān)于Idea為java程序添加啟動參數(shù)(含:VM?options、Program?arguments、Environment?variable)的相關(guān)資料,需要的朋友可以參考下2022-12-12SpringBoot使用Aspect切面攔截打印請求參數(shù)的示例代碼
這篇文章主要介紹了SpringBoot使用Aspect切面攔截打印請求參數(shù),本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-07-07