0

I need to have method that accepts let say 3 input parametars.

Calculate_Salary(int ratio, int vocationDays, int travelDays)

Many of the people do not travel, and rearly use vocation days in that case I want to call the functions in the best way (let say like in C++ only with one parametar, and other two will have default values)

There are planty of way to implement it I know (call method with zero values, overload it, implement default valuses in the body of method ). And note. it is simple with ints, it is more complex with the objects.

Calculate_Salary (ratio)

Which is the safest and fastest soulution, and is there something "new" in Java that can make this happen easy?

Thanks

Gaj Julije
  • 1,538
  • 15
  • 32

1 Answers1

1

As far as I know there is no solution that makes it really easy. But overloading is by far the best implementation you can do, moreover it is really easy, therefore I would go with this.

Moreover you do not need to implement a whole new function, simply call the first method with the default parameters you want.

OffByOne
  • 47
  • 4
  • Consider adding this as a comment and not an answer (or prepare for some downvotes) – Oozeerally Mar 23 '21 at 09:45
  • 1
    Sorry, would do this, but I do not have enough reputations. :( I would neet 50 to comment. Therefore I think it is harsh to get a downvote. I simply want to help and this is the only solution to add my comment. – OffByOne Mar 23 '21 at 09:47
  • @OffByOne I understand, hope that you will get it soon. – Gaj Julije Mar 23 '21 at 09:54