Possible Duplicate:
Does Java support default parameter values?
Is it possible to do something like this
private void function(Integer[] a, String str = "")
like in PHP. If I don't provide str, it will just be empty. In PHP it's possible, in JAVA it gives me error. Or the only solution here is to create two methods like this?
private void function(Integer[] a, String str)
private void function(Integer[] a)
Exacly, there is no other option than:
private void function(Integer[] a, String str) {
// ...
}
private void function(Integer[] a) {
function(a, "");
}
Declare your method with var agrs
private void function(Integer[] a, String... s)
Remember, var args should always be the last argument of the method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With