Created
January 7, 2016 05:59
-
-
Save JakeWharton/14547311b1f145cb0695 to your computer and use it in GitHub Desktop.
Covariant return types generate an extra method in bytecode. This compounds in each subclass further specializing the type.
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
interface Thing { | |
Object thing(); | |
} | |
class CharSequenceThing implements Thing { | |
@Override public CharSequence thing() { | |
return "CharSequence!"; | |
} | |
} | |
class StringThing extends CharSequenceThing { | |
@Override public String thing() { | |
return "String!"; | |
} | |
} |
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
$ 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