Work around Java's static method dispatching without Double Dispatch/Visitor patterns

末鹿安然 提交于 2019-12-06 01:26:04

Of course you could always use reflection to find the most specific version of the method that applies, but that could get hairy real quick.

But if those two calls result in entirely different behaviour, then Foo is either designed to be used in a visitor pattern (i.e. with double dispatch) or it is broken.

You could take a look at the Java MultiMethod Framework. It's pretty much a layer around what you're proposing, but atleast it's abstracted into a logical module that's not your responsibility?

(As far as I'm aware, there's no clean way to do this without resorting to reflection/instanceof hacking)

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