如何在Kotlin中调用具有相同名称的类方法中的全局函数?

时间:2018-01-10 09:43:07

标签: kotlin

我的情况是我需要具有与全局函数相同名称的全局函数和对象。

类似的问题:如果我有一个伴侣对象怎么办?

简单示例:

file:fooBar.kt

fun foo(){} //global foo
fun bar(){} //global bar

class FooBar {

   fun foo(){
       foo() //this makes me a recurrence but I want to call global foo here
   }

   fun bar(){
       bar() //this makes me a recurrence but I want to call global bar here
   }

    companion object {
       fun foo() {
           bar()// how to call global bar here?
       }
    }
}

修改

与功能有关的问题,但解决方案与变量

相同

0 个答案:

没有答案