GitHub - littleJava/delegatej: annotation based Java delegate
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
The artifact will be found in target directory.