Richard Hayward wrote:
Although my attempt at a generic version of the method, dogsBark2, does compile, attempting to call it with arguments that are exclusively all List<Dog> or all List<Poodle> won't compile.
The reason it doesn't compile is because the compiler can't find a T that satisfies the calling parameters. As you know, Poodle IS-A Dog, so, a Poodle instance can be used in place of a Dog instance. However, you are not passing Poodle and Dog instances; you are passing List<Poodle> and List<Dog> instances... and there isn't a IS-A relationship between List<Poodle> and List<Dog>.
Technically, you can handle the two parameter case via two generics ... like so ...
... but this adds complexity, and it only handles the two parameter case. You will need to have overloaded methods for the other cases. And since, I used a variable arity method, you will theoretically need an infinite number of overloaded methods with an infinite number of generics ...
Henry
PS... I gave you a
cow for your investigations. Good Job.