Created
December 3, 2018 17:59
-
-
Save odrotbohm/245298e5294f226343ad32778c468fd0 to your computer and use it in GitHub Desktop.
This file contains 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
class Sample { | |
public this someMethod() { | |
// … | |
return this; | |
} | |
} | |
class Subtype extends Sample {}; | |
Subtype instance = new Subtype(); | |
Subtype result = instance.someMethod(); // Does obviously not compile | |
// Alternatives | |
// - Override someMethod() in Subtype and cast to Subtype | |
// - Use self referential generics Sample<T extends Sample<T>> and T someMethod() { return (T) this; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment