For different types of arguments, there is 3-dots :
public void foo(Object... x) {
String myVar1 = x.length > 0 ? (String)x[0] : "Hello";
int myVar2 = x.length > 1 ? Integer.parseInt((String) x[1]) : 888;
}
Then call it
foo("Hii");
foo("Hii", 146);
for security, use like this:
if (!(x[0] instanceof String)) { throw new IllegalArgumentException("..."); }
The main drawback of this approach is that if optional parameters are of different types you lose static type checking. Please, see more variations .