↓だと型が定まらなくてコンパイルエラー。 import Foundation class Cat { @objc func nya() -> Int { return 3 } } class Dog { @objc func wan() -> Int { return 4 } } class Foo { @objc func wan() -> Double { return 5 } } func f(_ a: AnyObject) { let x = a.nya() let y = a.wan print(type(of: x), x) print(type(of: y), y) } f(Cat())
wan-nya-dynamic.swift:15:13: error: ambiguous use of 'wan()' let y = a.wan ^ wan-nya-dynamic.swift:7:16: note: found this candidate @objc func wan() -> Int { return 4 } ^ wan-nya-dynamic.swift:10:16: note: found this candidate @objc func wan() -> Double { return 5 } ^