Skip to content
MultiJ – Multimethods for Java
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
multij-core
multij-processor
multij-test
.gitignore
LICENSE
README.md
pom.xml

README.md

MultiJ

MultiJ provides multi-methods to Java.

Example

Multi-methods are defined as methods in a Java interface with the annotation @Module.

@Module
interface Example {
    default int test(Object o) {
        return 1;
    }
    default int test(String s) {
        return 2;
    }
}

The multi-method test is invoked by first creating an instance of the module and then invoking any of the test methods on the instance. MultiJ will select the most specific method with respect to the runtime types of the arguments.

Example example = MultiJ.instance(Example.class);
Object o = "hello";
int x = example.test(o); // x = 2

Doing the same thing on a regular Java object would not generate the same result.

Example example = new Example() {};
Object o = "hello";
int x = example.test(o); // x = 1
You can’t perform that action at this time.