Skip to content

Instantly share code, notes, and snippets.

@fhanik
Created April 25, 2018 20:55
Show Gist options
  • Save fhanik/915a9792b619049b380cd81000bdd84b to your computer and use it in GitHub Desktop.
Save fhanik/915a9792b619049b380cd81000bdd84b to your computer and use it in GitHub Desktop.
Subclass in super class
public class Test {
public static void main(String... args) throws Exception {
C c1 = new C()
.<C>something()
.<C>somethingElse()
.<C>anotherSet();
C c2 = new C()
.<C>anotherSet()
.<C>something()
.<C>somethingElse();
C c3 = new C()
.<C>anotherSet()
.<C>something()
.<C>somethingElse();
}
public static class A {
public <T> T something() {
return (T)this;
}
}
public static class B extends A {
public <T> T somethingElse() {
return (T) this;
}
}
public static class C extends B {
public <T> T anotherSet() {
return (T) this;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment