Created
October 11, 2010 01:27
-
-
Save ksky/619806 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// g100pon #54 duck typing | |
class Dog { | |
void cry() { println "Bowwow!" } | |
} | |
class Cat { | |
void cry() { println "Meow!" } | |
} | |
// DogとCatは共通のスーパークラスもインタフェースも持たないが、以下のように扱える(Javaでは無理) | |
void kick(obj) { obj.cry() } | |
kick(new Dog()) | |
kick(new Cat()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment