3 ms·
shrug. This seems like a pretty standard use of the ternary operator to me. I mean, just google examples of Comparator, and you'll find tons of examples like th
by msluyter 12y ago
shrug. This seems like a pretty standard use of the ternary operator to me. I mean, just google examples of Comparator, and you'll find tons of examples like this:
@Override
public int compareTo(Object arg0) {
Country country=(Country) arg0;
return (this.countryId < country.countryId ) ? -1:
(this.countryId > country.countryId ) ? 1:0 ;
}
(http://www.javacodegeeks.com/2013/03/difference-between-comparator-and-comparable-in-java.html http://www.javacodegeeks.com/2013/03/difference-between-comp...)
But that's orthogonal to my point, which is that lambdas offer significant improvements to readability because they remove the irrelevant cruft and simplify the code.
- Igglyboo 12y agoI'd have to agree, the GP is very bloated when a simple ternary will suffice.
- jbergens 12y agoAnd lambdas (or similar) has existed in C#, Python, Scala, Javascript and other languages for years. I still thinks this means that those languages has had large benefits compared to Java (7 and older). Now that Java 8 has lambdas even Java developers can learn to write better and more readable code. I also thinks that Java 8 is good enough for most projects now but Java 7 wasn't. Just my thinking.