Is it possible to insert a parameter in a function depending on a boolean value?
For example, I have this piece of code:
Math.min(boolA ? doubleValueA, boolB ? doubleValueB);
Thanks in advance!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use a default value (such as Double.MAX_VALUE) if
boolAorboolBis false:Edit
If you have a list of variables that you want to find the minimum, but only if the corresponding boolean variable is set, load the list into an array and find the minimum:
Edit 2
This can also be applied in general to other functions. Selectively add your parameters to an array, and pass the array to the function. If you have control over the function definition, you can use variable arguments to make it simpler.