everyone! I have two methods which are overloads in the same class.
If I run the below code, I got the error "The method is ambiguous for the type FruitList"
I can't do this:
sample.getFruit((Fruit)null);
nor this:
sample.getFruit((String)null);
I cannot change sample.getFruit(null);
How can I solve this problem??
sample = new FruitList(null);
sample.getFruit(null);------> error
public class FruitList{
private Fruit head;
public FruitList(Fruit head){
this.head = head;
}
public void getFruit(Fruit object){
}
public Fruit getFruit(String name){
}
}
public class Fruit{
private int amount;
private String name;
public Fruit(int amount, String name){
this.amount = amount;
this.name = name;
}
}