Last active
January 29, 2016 10:28
-
-
Save banterCZ/f647dd892e22103472e7 to your computer and use it in GitHub Desktop.
"Because Groovy dispatches by the runtime type, the specialized implementation of oracle(String) is used in the second case." "Wherever there’s a Java API that uses the static type Object, this code effectively loses the strength of static typing. ... This is why the Java type concept is called weak static typing" Source: Groovy in Action Second…
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
def oracle(Object o) { return 'object' } | |
def oracle(String o) { return 'string' } | |
Object x = 1 | |
Object y = 'foo' | |
assert 'object' == oracle(x) | |
assert 'string' == oracle(y) |
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
public class Dispatcher { | |
static String oracle(Object o) { return "object"; } | |
static String oracle(String o) { return "string"; } | |
public static void main(String... args) { | |
Object x = 1; | |
Object y = "foo"; | |
assert "object".equals(oracle(x)); | |
assert "object".equals(oracle(y)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment