Skip to content

Instantly share code, notes, and snippets.

@anthony-cros
Last active March 2, 2022 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthony-cros/8f7a34ab9849b0d1b104b7d414274061 to your computer and use it in GitHub Desktop.
Save anthony-cros/8f7a34ab9849b0d1b104b7d414274061 to your computer and use it in GitHub Desktop.
// $ cat Bar.java:
interface Bar<F> {
F f ();
default F bar() { return f(); }
}
// ==================================================
// $ cat Foo.java:
class Foo implements Bar<Foo> {
@Override public Foo f() { return this; }
}
// ==================================================
// $ cat Baz.java:
class Baz {
public static void main(String args[]) {
Foo foo = new Foo().bar(); // works without cast
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment