I would like to know what the error message in Eclipse means:
The constructor Case(Problem, Solution, double, CaseSource) is ambiguous
this compilation error is caused because the super constructor is undefined. in java, if a class does not define a constructor, compiler will insert a default one for the class, which is argument-less. if a constructor is defined, e.g. super(string s), compiler will not insert the default argument-less one.
The purpose of constructor is to initialize the object of a class while the purpose of a method is to perform a task by executing java code. Constructors cannot be abstract, final, static and synchronised while methods can be.
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.
To add on to other answers, it can be avoided by casting the argument to what is intended, e.g.:
class Foo { public Foo(String bar) {} public Foo(Integer bar) {} public static void main(String[] args) { new Foo((String) null); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With