How to make a method which accepts any number of arguments of any type in Java?
问题 I can see there is a way to have a method in Java which accepts any number of arguments of a specified type: http://www.java-tips.org/java-se-tips/java.lang/how-to-pass-unspecified-number-of-arguments-to-a-m.html but is there a way to make a method which accepts any number of arguments of any type? 回答1: All Java Objects extend the Object class. So you can make your function accept an Object array: public void func(Object[] args) { } Or if you want to be able to pass nothing: public void func