Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Inheritance Kotlin如何创建匿名类来实现具有2个方法的接口?_Inheritance_Kotlin - Fatal编程技术网

Inheritance Kotlin如何创建匿名类来实现具有2个方法的接口?

Inheritance Kotlin如何创建匿名类来实现具有2个方法的接口?,inheritance,kotlin,Inheritance,Kotlin,我有两种方法的接口: interface Human { fun talk() fun think() } 我想把这个接口的匿名实例传递给一个方法 我该怎么做?如果foo看起来像这样: fun foo(human: Human) { // ... } 您可以这样调用它,使用: 这个问题的答案有一个例子: foo(object: Human { override fun think() { // ... } override fu

我有两种方法的接口:

interface Human {
   fun talk()
   fun think()
}

我想把这个接口的匿名实例传递给一个方法


我该怎么做?

如果
foo
看起来像这样:

fun foo(human: Human) {
    // ...
}
您可以这样调用它,使用:


这个问题的答案有一个例子:
foo(object: Human {
    override fun think() {
        // ...
    }

    override fun talk() {
        //...
    }
})