Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.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
Java Kotlin:作为方法参数的接口_Java_Kotlin_Interface - Fatal编程技术网

Java Kotlin:作为方法参数的接口

Java Kotlin:作为方法参数的接口,java,kotlin,interface,Java,Kotlin,Interface,有没有其他方法可以像java中那样将接口作为参数传递给方法 public class ReverseList { interface NodeList { int getItem(); NodeList nextNode(); } void reverse(NodeList node) { } public static void main(String[] args) { } } 您可以创建一个属性 val

有没有其他方法可以像java中那样将接口作为参数传递给方法

public class ReverseList { 
    interface NodeList {
        int getItem();
        NodeList nextNode();
    }
    void reverse(NodeList node) {

    }
    public static void main(String[] args) {

    }
}

您可以创建一个属性

val handler = object: Handler {
override fun onComplete() {

}

}

为什么您需要一个替代方案?正如在上面的代码段中一样,将接口作为方法参数传递是非常有用的。是的,您刚刚证明了我的观点。你不需要其他选择。你应该这样做-接受一个接口作为参数。但是我不知道如何在Kotlin中这样做,因为我正在Kotlin中工作,将Intellij中的java代码保存在任何Kotlin文件中:p。投票结束问题。这与上述代码有何联系?你能举例说明一下吗?我不知道为什么这被否决了。