开发者

Utilising Javassist to provaide overloading based on return type

Ive used Javassist to dynamically change the return type of a function call, but its not working.

Ive got a call that is defined in the source code as simply:

Boolean getResult(){return true;}

But then at run time I dynamically change it to:

String getResult(){return "true"}

I then call it as:

Object o = myobject.getResult();

And get a MethodNotFou开发者_JS百科nd exception. If I use reflection I can see my new method on the object, but the call is failing, apparently because its somehow bound to the old return type.

If I call the new method reflectively (slight pseudocode..):

Method m = myobject.getClass.GetDeclaredMethods().(...find method named GetResult...)

Object o = m.invoke(myObject);

Then all works fine, and I can switch between manipulated and non manipulated byte code without issue, and I can see that the type of O is either String or Boolean accordingly.

Any ideas why?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜