Sunday, May 26, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...