【发布时间】:2021-01-14 21:06:48
【问题描述】:
我是 Kotlin 的新手。我有课程,我想在另一个课程中调用函数我尝试使用example 中的答案,但它给了我expecting member declaration error
如何使用它?
这是我的课
class MyClass() {
//Do stafff
val msg="Text"
MyObject.sendMsg("msg") //getting here error
}
//Another file i have this object file
object MyObject{
fun sendMsg(msg:String){
println("I get your message $msg")
}
}
【问题讨论】:
-
函数调用只能在函数/构造函数中进行,或者作为对属性的赋值。您的
MyObject.sendMsg("msg")电话只是在公开场合。