Originally posted by Andry Dub:
Hi, ranchers! Please explain me why first code compiles fine, but second generates compile time error? What is the main idea on this?
In the first code, you have a collection of instances that are base classes of Object (which can only be Object) and an Object instance. There is a type that matches the method that you defined (Object).
In the second code, you have a collection of instances that are sub classes of Object (which can be anything) and an Object instance. There isn't a type that matches the method that you defined.
The most interessant is that if you pass only one argument, the code compiles...
It would be more interesting... if you show us this code that compiles.
As for these two examples, well, they work because the compiler can find a type (or two types) that matches... which was not true in the original example.
Another option to get it to compile is by extracting the value from the collection itself -- hence, it is guarantee to match. (Of course, since the collection is empty, this will generate a runtime exception)
[ December 16, 2007: Message edited by: Henry Wong ]