Created
January 19, 2014 06:39
-
-
Save rajeevprasanna/8501298 to your computer and use it in GitHub Desktop.
Overloading return 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
package legalReturnTypes.overloadedMethods; | |
public class Bar extends Foo { | |
String go(int x) { | |
return null; | |
} | |
// Bar version of the method uses a different return type. That's perfectly | |
// fine. As long as you've changed the argument list, you're overloading the | |
// method, so the return type doesn't have to match that of the superclass | |
// version. | |
/* | |
* String go() { // Not legal! Can't change only the return type return | |
* null; | |
* } | |
*/ | |
} |
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
package legalReturnTypes.overloadedMethods; | |
public class Foo { | |
void go() { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment