Any good multimethod implementation for Java?

2k views Asked by At

I am wondering if there is any reasonably good multimethod implementation/library for Java like Lisp has.

I've found just this apparently frozen one: JMMF

3

There are 3 answers

0
Thomas On

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

0
Edwin Dalorzo On

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
davidji On

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.