Skip to content

Instantly share code, notes, and snippets.

@JakeWharton
Created January 7, 2016 06:32
Show Gist options
  • Save JakeWharton/5b3dbbc54c779a6bc6af to your computer and use it in GitHub Desktop.
Save JakeWharton/5b3dbbc54c779a6bc6af to your computer and use it in GitHub Desktop.
Unlike synthetic accessor methods, these synthetic covariant methods are hard or impossible to kill. Generics anyone?
interface Thing<T> {
T thing();
}
class CharSequenceThing implements Thing<CharSequence> {
@Override public CharSequence thing() {
return "CharSequence!";
}
}
$ javap -p Thing CharSequenceThing
Compiled from "GenericCovariants.java"
interface Thing<T> {
public abstract T thing();
}
Compiled from "GenericCovariants.java"
class CharSequenceThing implements Thing<java.lang.CharSequence> {
CharSequenceThing();
public java.lang.CharSequence thing();
public java.lang.Object thing();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment