Does it only complain about line 3? Somebody else has the same problem, and hasn't worked it out yet: here. Why do you think you are getting the warning?
I quote this from the article:
Why is there a compiler warning? Because in order to pass a and b to the method the varargs implementation needs to create an array - Collection<String>. But the generics implementation can't create a generified array, yet thats what the method is demanding. Arrrgh!!
So, instead of being helpful, Java creates an ungenerified Collection, and then the generics system warns us that it is an unchecked cast to make it a Collection<String>. But this conversion is all internal to the compiler! As far as the developer is concerned, there is nothing even vaguely type unsafe about what s/he is doing.
Now this is just headbangingly stupid. There is absolutely no risk of breaking the generics model here. No risk of a ClassCastException or ArrayStoreException. No, this is really just another case of generics being nearly completely broken with regards to arrays. And the varargs group didn't manage to realise/coordinate and get a decent implementation that works.
The problem for me is serious though. I am writing an API (commons-collections) that will be widely used, and will have to retain backwards binary compatibility. If I go with the varargs option (the logically correct choice), then every client of this method will get a useless java warning - not very friendly. The alternative is to go back to the original design and have three methods, an array, one-arg and two arg. And really thats just crap.
So, it seems it is basically because of the var-args method asList() trying to create a generics array in order to call the var-args method.
Since, the compiler generates this code, on compilation, we do not even get the line number for the warnings. Now that is something really ridiculous!!!
However, if you are really bothered about it, put this annotation at the top of your method:
Corrected misspelt hyperlink[/edit]
[ January 28, 2008: Message edited by: Campbell Ritchie ]