Last active
January 18, 2018 12:29
-
-
Save george-hawkins/a7fee06197a566beb30482f44522ca2d 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
// Compare IGroupable (with a type parameter) here with IGroupableX below (without a type argument). | |
// In what situation will the generics version buy you something that the non-generic version won't. | |
interface IGroupable<E extends IGroupable<E>> { | |
E fraction(double fraction); | |
public static class AlphaGroupable implements IGroupable<AlphaGroupable> { | |
@Override | |
public AlphaGroupable fraction(double fraction) { return null; } | |
} | |
public static class BetaGroupable implements IGroupable<BetaGroupable> { | |
@Override | |
public BetaGroupable fraction(double fraction) { return null; } | |
} | |
// Fraction returns an IGroupable that is not the containing class. | |
public static class GammaGroupable implements IGroupable<BetaGroupable> { | |
@Override | |
public BetaGroupable fraction(double fraction) { return null; } | |
} | |
} | |
interface IGroupableX { | |
IGroupableX fraction(double fraction); | |
public static class AlphaGroupable implements IGroupableX { | |
@Override | |
public AlphaGroupable fraction(double fraction) { return null; } | |
} | |
public static class BetaGroupable implements IGroupableX { | |
@Override | |
public BetaGroupable fraction(double fraction) { return null; } | |
} | |
// Fraction returns an IGroupable that is not the containing class. | |
public static class GammaGroupable implements IGroupableX { | |
@Override | |
public BetaGroupable fraction(double fraction) { return null; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment