Created
July 8, 2013 18:15
-
-
Save theJenix/5951143 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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