delegatej is annotation-based Java delegate implementation.
Inheritance sucks.
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"
install buildr if you haven't, and then
$ buildr package
The artifact will be found in target directory.