Skip to content

streamblocks/multij

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

MultiJ – Multimethods for Java

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%