“构造函数...是不明确的”意思? [英] What does "The constructor ... is ambiguous" mean?

查看:195
本文介绍了“构造函数...是不明确的”意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道Eclipse中的错误信息是什么意思:

I would like to know what the error message in Eclipse means:


构造函数Case(Problem,Solution,double,CaseSource)

The constructor Case(Problem, Solution, double, CaseSource) is ambiguous


推荐答案

当您尝试实例化可应用于更多的类时,问题存在比一个构造函数。

The problem exists when you try to instantiate a class that could apply to more than one constructor.

例如:

public Example(String name) {
    this.name = name;
}

public Example(SomeOther other) {
    this.other = other;
} 

如果使用String对象调用构造函数,则有一个确定的构造函数。但是,如果您实例化新的示例(null),那么它可能适用于任何一个,因此也是不明确的。

If you call the constructor with a String object, there's one definite constructor. However, if you instantiate new Example(null) then it could apply to either and is therefore ambiguous.

同样可以应用于具有相似签名的方法。

The same can apply to methods with similar signatures.

这篇关于“构造函数...是不明确的”意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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