When to prefer a varargs list to an array?
问题 I'm implementing an API an have a method which you pass a list of paths where the program reads resources from public void importFrom(String... paths) { } I'm using varargs to make calling the method as convenient as possible to the user, like so obj.importFrom("/foo", "/foo/bar); Is this an appropriate use of varargs? Or is passing in an array better? 回答1: In your case varargs is just fine. You don't really need to make an array of the paths that you will be importing because there's nothing