yet another blog about computer, technology, programming, and internet

Sunday, January 27, 2013

Java and Lombok

Sunday, January 27, 2013 Posted by Ismail Habib 53 comments
If you are an Indonesian, it's pretty easy to make a connection between Java and Lombok. However, this post is not about that Java and Lombok, but rather for the Java programming language and Project Lombok.

One of the drawback of Java language is its verbosity. One very easy example can be found in any typical Java POJO.

public class Order{

  private long id;
  private String name;
  private int size;

  public Order(){
  }

  public Order(long id){
    this.id = id;
  }

  public long getId(){
    return id;
  }

  public void setId(long id){
    this.id = id;
  }

  public String getName(){
    return name;
  }

  public void setName(String name){
    this.name = name;
  }

  public int getSize(){
    return size();
  }

  public void setSize(int size){
    this.size = size;
  }

  @Override
  public String toString(){
    return String.format("%s %d %d", id, name, size);
  }
}


Already that much code just for a very simple structure with constructors, getters, setters, and toString method. This is where Lombok comes to save the day! Instead of writing that much code, you can have something like this:

@Data
public class Order{

  private long id;
  private String name;
  private int size;
}

...and that's it! A clean, nice code that is easy to maintain. The @Data annotation will tell Lombok to generate the constructor, getters and setters, toString method (and even equals and hashCode method!) all during compilation time! (instead of hiding the code in other file ala AspectJ). Since Lombok can be integrated with your IDE, you will not lose the nice content assist or any other feature that you currently enjoying.

There are several other features provided by Lombok (see: Lombok features), although personally for me, this one is going to be the one I use the most. I am not too scared of introducing Lombok dependency to my project since Lombok itself presented a nice way to stop using Lombok dependency with a tool called "delombok". By using delombok, all magically generated code will be written to the source code and the dependency to Lombok library will be removed.

The only drawback I can think of is whenever I rename one of the field name and the rest of code which refer to the getter/setter will also need to be updated manually (instead of having them automatically updated using a refactor tool in your IDE), but it is a very small price to pay (I guess).

53 comments:

  1. Agree. Lombok is cool. Why it is not a plugin for Eclipse???? :(

    ReplyDelete
  2. I also looked at Project Lombok but deemed it too risky to use (f.x. there are issues with the latest JDK). I also found the customisation features lacking, so I just released my own open source tool for generating java value objects (with getters, setters, constructors, equals, hash, compareTo and more) that used 100% standard java features, integrates with all java tools and is extremely customisable. You can check it out at "http://valjogen.41concepts.com". Let me know what you think?

    ReplyDelete
  3. Thanks for sharing this quality information with us. I really enjoyed reading.

    temple run 2 |  bloons tower defense 5 |  tank trouble | happy wheels 3

    traffic rider | Geometry Dash |  subway surfers |launcher |

    ReplyDelete
  4. Thanks for taking time to share this post.It is really useful.Continue sharing more like this.
    Regards,
    Java Training in Chennai

    ReplyDelete
  5. Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great posts, have a nice weekend!

    Java Training in Bangalore

    ReplyDelete
  6. You rock particularly for the high caliber and results-arranged offer assistance. I won't reconsider to embrace your blog entry to anyone who needs and needs bolster about this region.
    Java Training in Marathahalli

    ReplyDelete
  7. I and my friends were going through the nice, helpful tips from the blog then the sudden came up with an awful suspicion I never expressed respect to the website owner for those secrets.
    hadoop training in bangalore

    ReplyDelete
  8. QuickBooks 2018 Desktop rendition for Windows has been propelled and it is brimming with energizing and creative highlights and instruments. Besides, improvement to more established adaptation of the software is likewise made inside the new arrival of QuickBooks Enhanced Payroll Support
    2018 update. Give us a call on +1888-567-1159

    ReplyDelete
  9. The QuickBooks Point Of Sale Support Number was essentially made to help users get through their problems and issues that they might come face to face while their time in QuickBooks Point of Sale. The QuickBooks Point of Sale support number guides you through every single detail of every technical fault that you have been through. Our certified ProAdvisors are here at your service 24/7, around the clock to resolve your issues at the earliest.

    ReplyDelete
  10. To solve Quickbooks problems you can contact QuickBooks Technical Support 1888-396-0208 (Toll-Free) Quickbooks online payroll support phone QuickBooks Technical Support USA. Some time ago to oversee businessmen need to buckle down.

    ReplyDelete
  11. QuickBooks Tech variant is a champion among the most serious renditions of all the three, that is, QuickBooks Pro, Premier and Tech. This rendition of QuickBooks programming was arranged keeping the back related prerequisites of associations having a far reaching gathering of records as a fundamental need. Approach Quickbook Technical Support Number 1888-396-0208 and get assistance from our Technicians.

    ReplyDelete
  12. Move up to QuickBooks Support 2018 now and experience the most recent highlights including multi-screen support, batch receipt preparing, enhanced inquiry choice, mobile receipt process and that's only the tip of the iceberg. 2018 Setup, Installation and Updates. Pick your phone and dial our toll free number anytime, We are here to help you 24/7. Call QuickBooks Support Phone Number +1888-396-0208 whenever for QB Support

    ReplyDelete
  13. Quickbooks Enterprise Support 1800-291-2485. QuickBooks is most popular, advance, latest accounting management tools for small or medium enterprise all over the world. It can manage inventory, payroll, audit, financial transaction, tax calculation, balance sheet, pay the bill, crate pay slip, invoice.

    ReplyDelete
  14. These are actually wonderful some ideas in the blog. You have touched good quality points here. In whatever way continue writing.
    Java Training in Chennai | Java Training Institute in Chennai

    ReplyDelete
  15. I simply wanted to thank you so much again. I am not sure the things that I might have gone through without the type of hints revealed by you regarding that situation.
    Click here:
    Online training in USA

    ReplyDelete
  16. It is really a great work and the way in which u r sharing the knowledge is excellent. Thanks for helping me to understand basic concepts. Thanks for your informative article. Java Training in Chennai | Pega Training in Chennai

    ReplyDelete
  17. Quickbooks Enterprise Support Phone Number CANADA 1888-557-6950 offers industry-specific solutions, notably for contractors, manufacturing and wholesale, nonprofits, and retailers. Quickbooks Enterprise support stands unique in the market as it has got the best tool which can help us to fix our any kind of Quickbooks related issues. They help to resolve our problem quite instantly and easily.

    ReplyDelete
  18. QuickBooks users really need to understand how they may personalize the expertise for them selves, by choosing which template matches their Group and demands the ideal. To possess an ideal experience, they should connect with and rely upon QuickBooks 24 hour customer support to take care of the processes wanting to go. It's on account of reasons like these why QuickBooks is broadly referred to as a big accounting program, one that requires business owners and business owners to realize access to grade QuickBooks Customer Service support selection in any way moments.

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. MacBook Pro, MacBook, Apple iPhone, iPod, and so on which include gadget and therefore are a great deal used. These devices are favorites of gurus and kids. The primary reason being this is always that those people gadgets have a flexible and superb engineering on that the resolve assistance supplied by professionals here at iPhone apple customer service is amazing and can't be in contrast with practically another repair provider. This team of specialists is servicing from ten years in precisely the profile. The apple iphone customer service phone number experts irritated customers and also have served around 2 million distressed. Which is just another excuse that fixes service by Individuals professionals is great? Visit Here: https://p-tweets.com/JonLakes

    ReplyDelete
  21. Perched in the beautiful mountains of the Himalayas, Himachal Pradesh is nothing less than a tourist’s heaven. With all its amazing beauty and charm, this hills station has managed to attract numerous tourists to its close vicinity. Consisting of beautiful tourist website locations like Manali, Shimla, Dalhousie, Kullu, Dharamshala and much more, this place is an amazing site to visit. All these admirable locations are included in our Uttarakhand Holiday Packages so that you don’t miss anything. Visit Here: https://bit.ly/2SZE9t1

    ReplyDelete
  22. Thanks for sharing The Information The Information shared is very valuable Please keep Updating us Time Just went on redaing the article Python Online Training AWS Online Training Devops Online Training Data Science Online Training

    ReplyDelete
  23. intuit data protect is a subscription service that helps you protect your data from loss or damage due to virus, laptop theft, file corruption, fire, and so on. Your files are automatically backed up online over the Internet once a day, every day, at an automatically selected time to an offsite location. You can choose to back up just your QuickBooks file, or you can back up multiple QuickBooks files and any other data on your computer.

    ReplyDelete
  24. QuickBooks accounting software created a benchmark in the area of accounting & bookkeeping. In the past few years, the demand for this software increased so much that the Intuit has to double the productivity. In this post, we are going to discuss the quickbooks error code 80029c4a. This informative post includes topics like its causes & resolution.However, if the error code persists – you can contact the certified QuickBooks technicians of QuickBooks Error Support. Or you can get in touch with them by making a call on their toll-free number .i.e. +1(800)396-7703.

    ReplyDelete
  25. Thenutritionsclinic It could sound pretty drastic the phrases 'fats camp' are pretty horrid to mention on your mind over and over once more. But, you have got permit yourself cross and this is what it has come too. You need to shed pounds earlier than you turn out to be so fats that you won't be capable of leave the house a person has to mention it and sorry if it sounds horrible. Attempt to consider the lack of weight in phrases of selfbeautification.
    https://thenutritionsclinic.com/

    ReplyDelete
  26. ketogenicpedia Relying on what is inflicting you ache, certain sports activities and moves may need to handiest make the symptoms and signs and symptoms worse. However, healthcare providers recommend that you need to hold the usage of your shoulder for a few mild sports activities because retaining it despite the fact that can also make your signs and symptoms worse.
    https://ketogenicpedia.com/

    ReplyDelete
  27. very well explained.Thanks for sharing.
    Java training in Nagpur

    ReplyDelete