Kotlin: Interface … does not have constructors

前端 未结 7 1134
长情又很酷
长情又很酷 2020-12-04 16:14

I am converting some of my Java code to Kotlin and I do not quite understand how to instantiate interfaces that are defined in Kotlin code. As an example, I have an interfac

7条回答
  •  自闭症患者
    2020-12-04 16:28

    class YourClass : YourInterface {  
        override fun getTest() = "test"    
    }
    
    interface YourInterface {
        fun getTest(): String
    }
    
    val objectYourClass: YourInterface = YourClass()
    print(objectYourClass.getTest())
    

提交回复
热议问题