This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
This is because the compiler cannot distinguish between the arguments of the two methods. (correct!!)
But how come this compiles:
Ok . This means that the compiler can distinguish between ArrayList<String> and ArrayList<String>... (var-arg). In the above code I have invoked the ArrayList<String> method. can anyone tell me how to invoke the ArrayList<String>... (Var-arg) method ? Please insert a line in my code
no because var args is equivalent to array.
so, in first case it sees both the arguments as arrays and in the second case one argument as array and other as a single arraylist.
SCJP 1.6 96%
Joined: Oct 30, 2009
to invoke var args arraylist version you can do something like this:
Joined: Oct 05, 2009
oh i got it .. but neha the code you wrote is giving warning for unchecked and unsafe operation. How am i going to compile it and verify the result? by the way why is the compiler warning about unsafe operation when i have written <String> in the method signature and everywhere else.
I have tried both , -Xlint:none and -nowarn but it again gives the warning . what to do ??
Joined: Jun 04, 2007
but then if I'm not wrong, the .class files should still get created despite compiler warnings. so you must be able to execute the code.
As far the reason for the warning, I think this might be the reason..
The compiler considers,
as something like
(since var-args are internally an array )
and now the type information is lost... So passing ArrayList<String> objects is considered as unsafe... Just my thought...
Joined: Oct 05, 2009
well you may be right Vishwanath , but what i figured out is that there is no problem with the method signature containing ArrayList<String>... The warning comes when i pass two arraylists, mylist1 and mylist2 together, and when i pass a single list mylist1 or mylist2 , there are no warnings .