重载解析度不明确.所有这些功能都匹配 [英] Overload resolution ambiguity. All these functions match

查看:210
本文介绍了重载解析度不明确.所有这些功能都匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试检查是否使用引用运算符在函数中初始化了Lateinit变量.在这种情况下,函数名称和变量名称相同.这样科特林就投掷

I tried to check, lateinit variable is initialized or not in a function using reference operator. The function name and variable name is same in this case. So that Kotlin throws

重载分辨率含糊不清.所有这些功能都匹配

Overload resolution ambiguity. All these functions match

例外.其实这段代码有什么问题吗?

exception. Actually what's wrong in this code?

class ABC

class MyClass {
    private lateinit var abc: ABC

    fun abc() {
        if(!::abc.isInitialized){
            println("Hello")
        }
    }
}

推荐答案

这是一个简单的名称冲突.编译器不知道您是指方法abc还是属性abc.重命名可解决此问题:

It's a simple name clash. The compiler does not know whether you're referring to the method abc or the property abc. A renaming fixes the problem:

class MyClass {
    private lateinit var abc: ABC

    fun abcFun() {
        val prop = this::abc
        if (!::abc.isInitialized) {
            println("Hello")
        }
    }
}

这篇关于重载解析度不明确.所有这些功能都匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆