This does bring up an interesting "sub-topic"... When there is a generic method, using a type <T>, which takes 2 different parameters of the generic type in question - how is <T> ascertained exactly?
Kind of hard to put into words, but, consider this shortened version of the original post:
As stated this compiles fine. Now, if we examine it, we have to come to the conclusion that for this specific invocation of the method, the generic type T has to be set to Object, and the reason the
String[] argument still applies is because it is "widened" up to an Object[]. (If T had been set to String here, the method call would cause a compiler error, since the Collection<Object> wouldn't match a Collection<String>).
So I reiterate my question, is there a specific way that <T> is ascertained? Or is it just so to speak "by the means available"?
I think this question is easily "tripped on" during a real
test, since one might be lured into thinking that for this method-call, the <T> of the method would be set to String, simply cus it's the first parameter appearing in the signature, and hence would generate a compiler error. If one doesn't take the time to consider different "variations" of the arguments, I'd say it's pretty easy to miss that this does in fact compile.
// Andreas