Tag: 函数调用

为什么我可以在Kotlin中省略函数调用?

在下面的例子中,我有2个函数,返回int。 在一种情况下,我有义务使用函数调用括号() ,在其他情况下,我被禁止使用它。 为什么以及如何控制? package kotlin.tests import java.util.ArrayList object MyObject { fun getValue(): Int { return 0 } } fun main() { val arrayList : ArrayList = ArrayList() println(arrayList.size()) // Expression ‘size’ of type ‘Int’ cannot be invoked as a function. The function ‘invoke()’ is not found println(MyObject.getValue) // Function invocation ‘getValue()’ expected }