The difference between Object... and Object
Introduction
When using indeterminate parameters in daily life, it can basically Object...
be understood as Object[] obj
a one- dimensional array
At the same time, Object...
it can only be used as a parameter of the method
Example:
As can be seen from the figure: text2
method and text
method use the same method to pass parameters, and text2
report an error
Object
The parameters in get can be usedArrays
example:
public void text(Object... params){
int length = params.length;
Object[] var=params;
List<Object> objects = Arrays.asList(var);
System.out.println(objects);
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
text("a","b","c");
}
Output result:
[a, b, c]