Sunday 26 May 2019

Is it possible for Java to create a method overloading with default arguments like Kotlin?

I have method with 10+ parameters actually I should write it with builder pattern. However, I think it will be a mess when converted to Kotlin. I wonder if there is a way to write java that could easily act like Kotlin does?



When we created fun with Kotlin like this



fun foo(bar: Int = 0, baz: Int) { /* ... */ }

foo(baz = 1) // The default value bar = 0 is used



How can we write similar method in java without written every possible?



E.g.



don't need to write



void foo(int bar, int baz){
...
}


void foo(int baz){
int bar = 0;
}

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...