日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > java >内容正文

java

编写Java程序 堆栈的接口_java - 错误:调用实现接口的通用方法时,java.lang.AbstractMethodError - 堆栈内存溢出...

發(fā)布時(shí)間:2025/3/12 java 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 编写Java程序 堆栈的接口_java - 错误:调用实现接口的通用方法时,java.lang.AbstractMethodError - 堆栈内存溢出... 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我正在嘗試使用javassist以編程方式創(chuàng)建和編譯實(shí)現(xiàn)接口的類(lèi)(在運(yùn)行時(shí))。

每當(dāng)我調(diào)用該動(dòng)態(tài)類(lèi)的實(shí)例時(shí),都會(huì)收到以下錯(cuò)誤消息:

java.lang.AbstractMethodError: FooImpl.test()Ljava/lang/Object;

這是我的界面

public class FooBarInterface {

public T getEntity();

}

這是一個(gè)示例實(shí)體

public class FooEntity {

@Override

public String toString() {

return "Hello, Foo!";

}

}

這是我以編程方式實(shí)現(xiàn)接口的方式

public void test() {

ClassPool classPool = ClassPool.getDefault();

CtClass testInterface = classPool.get(FooBarInterface.class.getName());

CtClass fooImpl = classPool.makeClass("FooImpl");

fooImpl.addInterface(testInterface);

CtMethod testMethod = CtNewMethod.make(

"public com.test.FooEntity getEntity(){" +

"return new com.test.FooEntity();" +

"}",

canImpl

);

fooImpl.addMethod(testMethod);

fooImpl.writeFile();

TestInterface test =

(TestInterface) fooImpl.toClass().newInstance();

System.out.println(test.getEntity());

}

如果我將實(shí)現(xiàn)的方法的返回類(lèi)型更改為Object,則不會(huì)收到錯(cuò)誤,如下所示:

CtMethod testMethod = CtNewMethod.make(

"public Object getEntity(){" +

"return new com.test.FooEntity();" +

"}",

canImpl

);

然后我成功地打了hello, Foo! 。 我可以將返回類(lèi)型更改為Object,但是我想進(jìn)一步了解為什么使用Foo類(lèi)型返回會(huì)產(chǎn)生AbstractMethodError 。

總結(jié)

以上是生活随笔為你收集整理的编写Java程序 堆栈的接口_java - 错误:调用实现接口的通用方法时,java.lang.AbstractMethodError - 堆栈内存溢出...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。