Method overloading with argument vararg of object class and array of object class

北城余情 提交于 2019-12-01 23:12:46

Object... is nothing but it is an array, that means same as defining Object[]

... (three dots) represents varargs in java.

We usually see this signature in main method like main(String... args)

So, having more than one method with same signature is not allowed in a class (compile time error). That is why you are seeing compile time error.

They are the same "under the hood". varargs (the ...) passes an array as a parameter:

It is still true that multiple arguments must be passed in an array, but the varargs feature automates and hides the process. Furthermore, it is upward compatible with preexisting APIs.

You can find it in the documentation here .

bfishman

Variable Length Arguments, like Object... are syntactic sugar. When used, for example:

flexiPrint("apple", "peach", "plum");

Then "apple", "peach", "plum" are actually turned into: `Object[]{"apple", "peach", "plum"}.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!