Skip to content

Instantly share code, notes, and snippets.

@theJenix
Created July 8, 2013 18:15
Show Gist options
  • Save theJenix/5951143 to your computer and use it in GitHub Desktop.
Save theJenix/5951143 to your computer and use it in GitHub Desktop.
public interface Accessor<T> {
public String getData();
}
public class ClassA {
private String superAwesomeData = "Woah.";
public String getSuperAwesomeData() { return this.data; }
}
public class ClassB {
public <T extends Accessor> void doStuff(T obj) {
doStuff(obj, obj)
}
public <T> void doStuff(T obj, Accessor<T> accessor) {
obj.getData();
}
public static void main(String[] args) {
final ClassA a = new ClassA();
new ClassB().doStuff(a, new Accessor<ClassA>() {
public String getData() {
return a.getSuperAwesomeData();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment