Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
659 views
in Technique[技术] by (71.8m points)

java - What does "The constructor ... is ambiguous" mean?

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

For example:

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

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...