Skip to content

Latest commit

 

History

History
50 lines (38 loc) · 951 Bytes

File metadata and controls

50 lines (38 loc) · 951 Bytes

delegatej

delegatej is annotation-based Java delegate implementation.

Why

Inheritance sucks.

Usage

Assume that there is an interface to implement:

public interface Executable {
    String execute(String name);
}

Now, we need to implement a runtime Annotation to declare our method:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Handle {
    String value();
}

Here, the class with our Annotation:

public class Runner {
    @Handle("runner")
    public String run(String name) {
        return "hello " + name;
    }
}

It's time to show our delegatej

Executable executable = delegate(Handle.class).to(Executable.class).trait(new Runner());
executable.execute("dreamhead"); // "hello dreamhead"

Build

install buildr if you haven't, and then

$ buildr package

The artifact will be found in target directory.