Skip to content

littleJava/delegatej

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

annotation based Java delegate

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published