ダック・タイピング
haXeでダック・タイピング。(厳密には違うかも?)
// Main.hx class Main { public static function test(foo:{function sound():String; var name:String;}) { neko.Lib.println(foo.sound()); neko.Lib.println("-- "+foo.name); } public static function main() { test(new Duck("Ronald")); test(new Cat("Kitty")); } } class Duck { public var name:String; public function sound():String { return "quack"; } public function new(name:String) { this.name = name + " Duck"; } } class Cat { public var name:String; public function sound():String { return "myaa"; } public function new(name:String) { this.name = name + " Cat"; } }