Bear Bibeault wrote:You first. What have you come up with on your own? What problems are you having with it?
Paul Clapham wrote:The correct way to refactor those five lines of code you originally posted is like this:
Paul Clapham wrote:
Using a ternary operator like you're trying to do will just make the code even more unreadable. So why would you want to do that?
Saral Saxena wrote:Hi folks ,
I have condition in my program...
Could you please help me in converting the above code as per ternary operator..!!
Jeff Verdegan wrote:
Saral Saxena wrote:Hi folks ,
I have condition in my program...
Could you please help me in converting the above code as per ternary operator..!!
Isn't this the second or third time you've asked this question?
Saral Saxena wrote:
could you please explain it in detail, as I am still not able to grasp it..!!
...
Just to explore that how ternary operator behaves..!!
Saral Saxena wrote:
Hi Jeff,
Just to explore the role of ternary operator...!!
Saral Saxena wrote: i do googling and gone through books also..!!
Saral Saxena wrote:
Hi Paul,
Paul Clapham wrote:The correct way to refactor those five lines of code you originally posted is like this:
could you please explain it in detail, as I am still not able to grasp it..!!
Paul Clapham wrote:
A detailed explanation of one line of code? Okay...
The isRewardsEnabled() method of the RewardsSupport class, or object, or whatever it is, returns a boolean value. Since you ask for a detailed explanation, we'll include the information that a boolean value can only be true or false. So this line of code takes that boolean value and returns it to the caller of whatever method the code is embedded in.
Jeff Verdegan wrote:writing a bunch of code to see how it works
Saral Saxena wrote:
so paul in this case it it is enables then we must pass return RewardsSupport.isRewardsEnabled(); but what about the other case..!!in which it is false...!! could you please explain in detail block as I have done above here, that will be a great help..!! thanks in advance..!!
Do not wait to strike till the iron is hot; but make it hot by striking....
Manoj Kumar Jain wrote:Really I don't understand what you want to ask or are you kidding, finally you are returning back the value of RewardsSupport.isRewardsEnabled(), if this is true then return true if this is false then return false. even method itself doesn't make much sense if you can directly use RewardsSupport.isRewardsEnabled() where you are calling this method.
Koen Aerts wrote:Ternary operators allow you to simplify writing simple conditional statements.
Saral Saxena wrote:
Jeff Verdegan wrote:
Saral Saxena wrote:Hi folks ,
Could you please help me in converting the above code as per ternary operator..!!
Isn't this the second or third time you've asked this question?
Hi Jeff,
Just to explore the role of ternary operator...!!
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Consider Paul's rocket mass heater. |