I'm read Deital's book :"Java How To Program", and in Generic Chapter the sentence is written:"If the compiler doesn’t find a method declaration that matches a method call exactly, but does find two or more methods that can satisfy the method call, a compilation error occurs". Can someone give me an example of the situation, because when i didn't success to get the above compile error. my code:
public class Animal
{
public Animal ()
{
}
public String bark()
{
return "Animal";
}
}
public class Dog extends Animal
{
public String bark()
{
return "howhow";
}
}
public class DogSon extends Dog
{
public String bark()
{
return "I'm Dog Son";
}
}
public class Test
{
public static void main(String[] args)
{
Test t = new Test();
DogSon d = new DogSon();
System.out.println(t.helpMethod(d));
}
public <T extends Dog> String helpMethod(T dog)
{
System.out.println("aaa");
return dog.bark();
}
public <T extends Animal> String helpMethod(T animal)
{
return animal.bark();
}
}
Since there isn't method that get exactly son object, and there are two generic methods that can be suit here. Isn't this the situation Deital talking about?