Sunday, 10 September 2017

java - private void function(Integer[] a, String str = "") like in PHP











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)

Answer



Exacly, there is no other option than:



private void function(Integer[] a, String str) {
// ...
}


private void function(Integer[] a) {
function(a, "");
}

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...