The difference between Object... and Object

The difference between Object... and Object

Introduction

When using indeterminate parameters in daily life, it can basically Object...be understood as Object[] obja one- dimensional array

At the same time, Object...it can only be used as a parameter of the method

Example:

image-20230405175817549

As can be seen from the figure: text2method and textmethod use the same method to pass parameters, and text2report an error

ObjectThe 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]

Guess you like

Origin blog.csdn.net/qq_48778364/article/details/129974583