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.
To further clarify, the reason there is a compile error, is because the compiler can't find a type that matches both parameters. It doesn't mean that the collection is invalid, as you can see by Alexsandra's examples.
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)
Henry [ December 16, 2007: Message edited by: Henry Wong ]