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

Sunday, January 27, 2013

Java and Lombok

Sunday, January 27, 2013 Posted by Ismail Habib 87 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).

87 comments:

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

    ReplyDelete
    Replies
    1. I have read your blog its very attractive and impressive. I like it your blog.

      Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

      Java Online Training Java Online Training Core Java 8 Training in Chennai Core java 8 online training JavaEE Training in Chennai Java EE Training in Chennai

      Delete
    2. Java Online Training Java Online Training Java Online Training Java Online Training Java Online Training Java Online Training

      Hibernate Online Training Hibernate Online Training Spring Online Training Spring Online Training Spring Batch Training Online Spring Batch Training Online

      Delete
    3. Java Training Institutes Java Training Institutes Java EE Training in Chennai Java EE Training in Chennai Java Spring Hibernate Training Institutes in Chennai J2EE Training Institutes in Chennai J2EE Training Institutes in Chennai Core Java Training Institutes in Chennai Core Java Training Institutes in Chennai

      Delete
  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 sharing this quality information with us. I really enjoyed reading.

    baixar whatsapp

    ReplyDelete
  6. When looking for the best yachting shirts in 2017, comfort should be one of the most important considerations. After all, you would surely not want to be in a situation wherein you would want to immediately get rid of your shirt because of the comfort that it provides. One thing that makes this shirt very comfortable is the fact that it is made from 100% cotton pique. It also has the right fit, provided that you choose the size that is right for your body. The Best Polo Shirt is well-stitched, which can provide you with the assurance that it can be used longer.

    ReplyDelete
  7. The article you have shared here very awesome. I really like and appreciated your work. I read deeply your article, the points you have mentioned in this article are useful

    lennyfacetext.com

    ReplyDelete
  8. 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
  9. 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
  10. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.


    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

    ReplyDelete
  11. 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
  12. Thanks a lot very much for the high quality and results-oriented help.
    I won’t think twice to endorse your blog post to anybody who wants
    and needs support about this area.

    java training in chennai


    java training in bangalore

    ReplyDelete
  13. It is really interesting for me to read this article. Thanks for it. I like such topics and everything connected to them.
    SEO Experts in Bangalore
    Best SEO Services in Bangalore
    low cost seo packages

    ReplyDelete
  14. We Provide Best Packers And Movers Kolkata List for Get Free Best Quotes, Compare Charges, Save Money And Time, Household Shifting Services @ Packers and Movers Kolkata

    ReplyDelete
  15. The young boys ended up stimulated to read through them and now have unquestionably been having fun with these things.
    safety course in chennai

    ReplyDelete
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. My rather long internet look up has at the end of the day been compensated with pleasant insight to talk about with my family and friends.
    safety course in chennai

    ReplyDelete
  22. 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
  23. With QuickBooks Accounting Software,Your business will reach new height and if there is any problem while using this accounting software you have best option to get QuickBooks Support Phone Number with a quick online solution by our thechnical expert.

    ReplyDelete
  24. Downloads & Updates. Get a trial versionProAdvisors. Download QuickBooks Desktop ... Why isn't my version of QuickBooks available to download?.So call our tollfree number and get direct link to Download QuickBooks to Latest Versions

    ReplyDelete
  25. 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
  26. 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
  27. 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
  28. 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
  29. 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
  30. This comment has been removed by the author.

    ReplyDelete


  31. ارخص شركة رش مبيدات بالمدينة المنورة شركة رش مبيدات حشرية بالمدينة المنورة
    ارخص شركة رش مبيدات بالدمام شركة رش مبيدات حشرية بالدمام
    ارخص شركة مكافحة الحمام بالمدينة المنورة شركة تركيب طارد الحمام بالمدينة المنورة

    ReplyDelete
  32. 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