开发者

Any good multimethod implementation for Java?

I am wondering if there is any reasonably good multimethod implemen开发者_如何学Ctation/library for Java like Lisp has.

I've found just this apparently frozen one: JMMF


You could use Clojure which runs on the JVM and has built-in support for multimethods.


I created this library which allows you to implement a Java interface using multimethods, by creating a proxy that satisfies the interface. I'm using it in a few projects and it's reasonably predictable, but read the documentation: Multimethods in Java can behave strangely.


There are a few valid alternatives to deal with the multiple dispatch problem, and perhaps these alternatives pretty much justify why it has not been implemented in the language. So, you can use the classical visitor pattern or you can use certain amount of reflection.

There is an outdated MultiJava Project that implemented mutiple dispatch support in Java and there are a couple of other projects out there using reflection to support multimethods in Java: Java Multimethods, Java Multimethods Framework. Perhaps there are even more.

You could also consider an alternative Java-based language which does support multimethods, like Clojure or Groovy (these links point to examples).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜