overriding methods without subclassing in Java

我们两清 提交于 2019-11-30 13:11:07

In this case the XStream class is an anonymous inner class. Then you're overriding the method of your anonymous XStream class.

The new implementation for

wrapMapper(MapperWrapper next)

method is limited for this instance xstream

XStream xstream

this type of overriding is creating a class that extends XStream, that's why it is called Anonymous, do not have a name and you can not have a reference for it.

That is called an "Anonymous class". You can find a lot of documentation about this special syntax on Internet. Good luck.

Search Google for Anonymous Inner Class in Java

That's pretty useful to implement interfaces or abstract Class methods on concrete objects

That's heavily used when working with threading (Runnable class)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!