I have the following scenario.. and I come across the similar scenario many a times. Which is more preferable of the following two options?
Option-1:
String result = ( getDetails(...) == null ) ? "" : getDetails(...);
Option-2:
String returnValue = getDetails(...);
String result = ( returnValue == null ) ? "" : returnValue;
Which is more preferable and/or a good practice.?
Yes, You can call a function but never store the returned value by that function in java. But it will just unnecessarily consume processing time. Because you will not be achieving what you want to achieve by first declaring that you want some processing to be done by method and return a final output.
To use the return value when calling a method, it must be stored in a variable or used as part of an expression. The variable data type must match the return type of the method.
A Function is the Python version of the routine in a program. Some functions are designed to return values, while others are designed for other purposes. We pass arguments in a function, we can pass no arguments at all, single arguments or multiple arguments to a function and can call the function multiple times.
Imho The second one is better because it's avoiding calling getDetails(...)
method twice.
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