Skip to content

Instantly share code, notes, and snippets.

@Zikoel
Created June 26, 2016 14:31
Show Gist options
  • Save Zikoel/9a79cc489af87f386434756f9b5be922 to your computer and use it in GitHub Desktop.
Save Zikoel/9a79cc489af87f386434756f9b5be922 to your computer and use it in GitHub Desktop.
Java generics
public class A {
public A() {
MainApp.decorateMyClass(this);
}
}
public class B {
public B() {
MainApp.decorateMyClass(this);
}
}
public interface Decorator() {
void decorate(A a);
void decorate(B b);
}
public class MainApp {
private Decorator decorator;
private static MainApp mainApp;
public MainApp() {
mainApp = this;
decorato = getConcreteFromSomewhere();
}
public static <T> void decorateMyClass(Class<T> clazz) {
decorator.decorate(clazz);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment