Last active
August 29, 2015 14:00
-
-
Save jeffscottbrown/11384337 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 MyInterface<T extends MyInterface> { | |
T someMethod(); | |
} | |
public class FirstWidget implements MyInterface<FirstWidget> { | |
public FirstWidget someMethod() { | |
return this; | |
} | |
} | |
public class SecondWidget implements MyInterface<SecondWidget> { | |
public SecondWidget someMethod() { | |
return this; | |
} | |
} | |
public class Demo { | |
public void someMethod(FirstWidget w) { | |
// the compiler knows that someMethod() will return a FirstWidget... | |
FirstWidget fw = w.someMethod(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment