Skip to content

Instantly share code, notes, and snippets.

@osscontributor
Last active August 29, 2015 14:00
Show Gist options
  • Save osscontributor/11384337 to your computer and use it in GitHub Desktop.
Save osscontributor/11384337 to your computer and use it in GitHub Desktop.
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