1. 2016-03-09 - Reduce boilerplate code with Lombok; Tags: Reduce boilerplate code with Lombok
    Loading...

    Reduce boilerplate code with Lombok

    On the Javaland Conference 2016 I visited an interesting presentation about RESTful Hypermedia APIs by Kai Tödter. A really refreshing and pragmatic view how to benefit from Hypermedia. An additional insight was the Project Lombok.

    Using RESTful Webservices often involves having dedicated value objects or DTOs, that aren’t full blown. Writing getter and setters, having constructors, equals, hashCode and toString methods are for maintenance mandatory. Lombok is great way to reduce the boilerplate code, so you can focus on the real code. Check it out for yourself!

  2. 2015-10-18 - Redundant conditional expression with the ternary operator; Tags: Redundant conditional expression with the ternary operator
    Loading...

    Redundant conditional expression with the ternary operator

    This operator (?) is also known as the ternary operator because it uses three operands. Instead of an if-then-else statement this operator can make your code more readable, when something is so simple you don’t want to waste many lines for.

    I have stumbled recently over this code in a stackoverflow post:

    String str = "Y";//or else "N"
    boolean isManager = (str.equals("Y")) ? true : false;
    

    Critical points from my point of view:

    • parenthesis is unnecessary
    • a control flow issue, since str.equals("Y") already returns true or false, the use of the ternary operator is redundant

    Clean code

    String str = "Y";//or else "N"
    boolean isManager = str.equals("Y");