Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Covariant return types generate an extra method in bytecode. This compounds in each subclass further specializing the type.
interface Thing {
Object thing();
}
class CharSequenceThing implements Thing {
@Override public CharSequence thing() {
return "CharSequence!";
}
}
class StringThing extends CharSequenceThing {
@Override public String thing() {
return "String!";
}
}
$ javap -p Thing CharSequenceThing StringThing
Compiled from "CovariantReturnTypes.java"
interface Thing {
public abstract java.lang.Object thing();
}
Compiled from "CovariantReturnTypes.java"
class CharSequenceThing implements Thing {
CharSequenceThing();
public java.lang.CharSequence thing();
public java.lang.Object thing();
}
Compiled from "CovariantReturnTypes.java"
class StringThing extends CharSequenceThing {
StringThing();
public java.lang.String thing();
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
You can’t perform that action at this time.