I need to pass multiple parameters in a function. My requirement is the parameter value should not be NULL. If the parameter is NULL pass "TBD" instead.
e.g.
getBookInfo (string bookId, string bookName, string bookAuthor)
//if any of the parameters is NULL, pass "TBD" string in parameter
How can I do this? Can I do this using ternary operator, and if so, how?
So, we can define a Predicate that will check for the null value of a String and pass this Predicate to the filter() method. Consequently, the filter will filter out those null values from the original Stream.
You can pass NULL as a function parameter only if the specific parameter is a pointer. The only practical way is with a pointer for a parameter. However, you can also use a void type for parameters, and then check for null, if not check and cast into ordinary or required type.
When the parameter has no value, SQL interprets it as null in your code. Null means no value. You can fix this problem by adding a code to fix the null case. There are 3 ways to resolve this problem: you can either coalesce the null value or add a logic to execute another operation.
There's no null in Python. Instead, there's None. As stated already, the most accurate way to test that something has been given None as a value is to use the is identity operator, which tests that two variables refer to the same object. In Python, to represent an absence of the value, you can use a None value (types.
Try doing it this way when calling your method:
getBookInfo (bookId ?? "TBD", bookName ?? "TBD", bookAuthor ?? "TBD");
The ternary operator ?:
is a waste when you can use the null coalescing operator ??
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With