As the two functions
foo(Object... obj)
{
for(int i=0;i<obj.length;i++)
System.out.println(obj[i]);
}
and
foo(Object [] obj)
{
for(int i=0;i<obj.length;i++)
System.out.println(obj[i]);
}
and the function call can be done
foo(obj,str,1);
foo({obj,str,1});
respectively , perform the same function and the latter existed from the very starting of java then why the Object… obj was implemented
Which one is better and why?
The
...functions are a kind of syntactic sugar – they offer more convenient syntax (no braces) without alter anything else, including performance. The compiler does the same thing behind the scene, letting you use more convenient syntax.