Fork us on GitHub

TIP: Using Lombok and Other tools

You can leverage tools like Lombok surprisingly easily
TIP: Using Lombok and Other tools

TIP: Using Lombok and Other tools

A few weeks back maaartinus asked on stack overflow whether we can get lombok working with Codename One. After a short back and forth it seems that this was as easy as I’d hoped and he was able to get it working without a change.

Personally, I like our approach of property objects more but that’s obviously a matter of taste. Lombok works by processing the bytecode after compilation to convert annotations to terse code. E.g. this Java code using Lombok:

@Getter @Setter @NonNull
private List<Person> members;

Would be similar to this regular Java code:

private List<Person> members;

public Family(final List<Person> members) {
    if (members == null) throw new java.lang.NullPointerException("members");
    this.members = members;
}

public List<Person> getMembers() {
    return members;
}

public void setMembers(final List<Person> members) {
    if (members == null) throw new java.lang.NullPointerException("members");
    this.members = members;
}
I took the code sample above from here

That’s pretty nice and it has some other features that hide some of the verbosity of Java.

As mentioned in the answer adding Lombok to a Codename One application is pretty easy:

  • Just add the lombok.jar to the build path which you can find in the project settings for the native IDE

  • In the build.xml replace compiler="modern" with compiler="extJavac"

  • Add the path to lombok.jar to the classpath in the build.xml (this might not be necessary in NetBeans)

Doing this for Other Things

Lombok is just one of a huge set of bytecode manipulation tools that work statically. I’m sure there are many other tools like that in the wild that would "just work" and we never got around to test them.

If you have a pet tool in your toolbox check it out and see if it works with Codename One. You might be surprised.

Share this Post:

Posted by Shai Almog

Shai is the co-founder of Codename One. He's been a professional programmer for over 25 years. During that time he has worked with dozens of companies including Sun Microsystems.
For more follow Shai on Twitter & github.