Skip to content

Instantly share code, notes, and snippets.

@ksky
Created October 11, 2010 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksky/619806 to your computer and use it in GitHub Desktop.
Save ksky/619806 to your computer and use it in GitHub Desktop.
// 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