DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Enhancing Java Application Logging: A Comprehensive Guide
  • Effective Tips for Debugging Complex Code in Java
  • Techniques You Should Know as a Kafka Streams Developer
  • How to Configure, Customize, and Use Ballerina Logs

Trending

  • Rust, WASM, and Edge: Next-Level Performance
  • Scaling Microservices With Docker and Kubernetes on Production
  • Advancing Your Software Engineering Career in 2025
  • Efficient API Communication With Spring WebClient
  1. DZone
  2. Coding
  3. Java
  4. Manifold vs. Lombok: Enhancing Java With Property Support

Manifold vs. Lombok: Enhancing Java With Property Support

Two decades ago, we worked on properties in Java. Lombok filled in that gap. Manifold aims to solve this same problem. Is it ready for prime time?

By 
Shai Almog user avatar
Shai Almog
DZone Core CORE ·
Jun. 07, 23 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
4.3K Views

Join the DZone community and get the full member experience.

Join For Free

Today, we'll explore an intriguing aspect of Manifold: its property support. In comparison, we'll also examine Lombok, a popular library that offers similar features. By analyzing the differences between these two projects, we can gain insight into their core philosophies and advantages. Let's dive in and discover how Manifold's property support stands out.

As always, you can find the code examples and additional resources for this post on my GitHub page.

Comparing Manifold and Lombok

Manifold and Lombok are very different projects, but they do overlap in a few areas. Properties are where the overlap is greatest, and the philosophical differences between the two shine out the most.

Let's explore these differences in detail, highlighting the strengths and limitations of each. The following table provides a high-level comparison:


Lombok Manifold
Maturity Old New
IDE Support All Major IDEs Supported IntelliJ/IDEA
Exit Strategy Easy None
Extensibility Challenging Modular
Scope Limited Extensive

Maturity, IDE Support, and Exit Strategy

Lombok has been around for quite some time, and many of its features were designed for older versions of Java. Consequently, some of its functionalities may no longer be relevant or applicable. Furthermore, Lombok's integration with modern IDEs can be limited, and converting Lombok code back to plain Java sources may not be straightforward. While Lombok provides essential boilerplate removal, it is often perceived as a temporary solution or "band-aid" due to its underlying approach.  

Manifold's Extensibility and Scope

Manifold offers a more extensible and pluggable framework with a well-designed architecture. While it may still face growing pains and limited IDE support, Manifold's flexibility allows for more ambitious projects and future enhancements. It leverages the strengths of Java's type system while providing unique features.

Property Support

Manifold's property support is based on a concept that has been discussed for decades in the Java community. However, reaching a consensus on the direction proved challenging, so a JEP never took hold. On a personal note, I was deeply involved with this discussion and strongly advocated for object properties. With Valhalla, it’s possible that object properties will become the golden standard moving forward. 

Manifold takes a more standard approach that aligns with other languages, such as C# and Kotlin, providing familiar and powerful property notation. This is good. It can provide short-term relief to the verbosity of getters and setters.

Differentiating Manifold's Property Support

To understand Manifold's property support, let's examine its equivalent code to the Lombok example. This is a standard Plain Old Java Object (POJO). Notice the get and set methods? Those are standard Java properties, powerful but heavy on the boilerplate:

Java
 
public class HelloPojo {
    private int number;
    private String str;

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public String getStr() {
        return str;
    }

    public void setStr(String str) {
        this.str = str;
    }
}


We can write the same code using Lombok as such:

Java
 
@Getter
@Setter
public class HelloLombok {
    private int number;
    private String str;
}


The usage is identical:

Java
 
obj.setNumber(5);


This is problematic. You will notice we define the fields as private, yet suddenly a setNumber() method appears out of thin air. It feels weird. I get the logic, though. The creators of Lombok wanted it to be a drop-in replacement. You could write the rest of the code with setters, so if you choose to remove Lombok, you don’t need to edit the rest of the code. It still stands out as weird.

The Manifold equivalent is similar but has some nuances:

Java
 
public class HelloProperties {
    @var int number;
    @var String str;
}


One notable distinction is that Manifold's properties are defined at the individual field level rather than applying to an entire class. Although Manifold may introduce a similar feature to Lombok's Data annotation in the future, it does not currently exist. We need to explicitly define each property.

By default, Manifold makes the property private and generates public accessors (getters and setters). However, just like Lombok, Manifold allows customization through annotations. 

The big difference is in the usage. Unlike Lombol, Manifold enables accessing the property directly, eliminating the need for explicit method calls. This behavior applies not only to properties but also to regular setters and getters, creating a consistent and intuitive experience. For example, accessing Calendar.getInstance() as Calendar.instance or retrieving the time from an instance using timeInMillis instead of getTimeInMillis() showcases the syntactic clarity and conciseness offered by Manifold:

// In Manifold a property acts like field access
var properties = new HelloProperties();
properties.number = 5;

// even POJO getters and setters act like field access
var pojo = new HelloPojo();
pojo.number = 5;

// This is equivalent to Calendar.getInstance().getTimeInMillis()
var time = Calendar.instance.timeInMillis;   


Customizing Manifold Properties

Similar to Lombok, Manifold offers customization options for individual properties. By using val, a read-only property with only a getter can be defined, behaving similarly to a final field. Conversely, set defines a write-only property. Additionally, scoping preferences can be passed as arguments, influencing the generated methods' visibility.

This is an example class that customizes such scoping:

Java
 
public class HelloScoping {
    @val(PropOption.Package) int number = 5;
    final @set String str;
}


Which we can use, as such:

Java
 
var scoping = new HelloScoping();
scoping.str = "";
System.out.println(scoping.number);

// This line won’t compile due to “read only” property
scoping.number = 4;

// This line won’t compile due to “write only” property
System.out.println(scoping.str);


Encapsulation and Method Implementation

Despite the accessibility of properties in Manifold, encapsulation is not compromised. If a setter or getter method is explicitly implemented, Manifold recognizes the custom implementation and seamlessly interacts with the property. For instance, implementing setNumber() allows the code to treat access to the number field accordingly, maintaining consistent behavior throughout the codebase as such:

Java
 
public class HelloComputed {
    @var int number;
    @var String str;

    public void setNumber(int number) {
        this.number = number - 1;
    }
}


The following code will print 4:

Java
 
computed.number = 5;
System.out.println(computed.number);


Other Considerations

While both Lombok and Manifold offer useful features, it's important to consider some aspects that may influence your decision. Lombok provides annotations for generating equals, hashCode, and toString methods. It offers annotations that generate constructors, builder patterns, and loggers, all of which are currently missing from Manifold. 

Additionally, Lombok's @SneakyThrows annotation enables throwing checked exceptions without explicit declaration or handling. Manifold addresses this with a similar global configuration, disabling checked exceptions throughout the codebase. That might be a bit heavy-handed for most developers. However, it's worth noting that these are not direct equivalents and have different implications.

We can sum this up in the following table:


Lombok Manifold

Data & Value

✅

❌

Equals/Hashcode/toString

✅

❌

Constructors

✅

❌

Builders

✅

❌

Loggers

✅

❌

.?

❌

❌

Fluid Dot Syntax

❌

✅

Smart Scoping

❌

✅

Final Word

As we wrap up our exploration of property support in Manifold and Lombok, it's evident that both projects bring unique approaches to enhance Java development. While Lombok has been a popular choice, its limitations and legacy features may prompt developers to seek alternative solutions. On the other hand, Manifold's extensibility, architectural soundness, and distinctive features make it an enticing option for modern Java projects. Manifold is young and still has some limitations in this particular department. That might hinder its adoption in the short term.

Personally, I’m still on the fence. I think Manifold has great potential here. I feel it's a better thought-out solution. Lombok feels a bit like a bandaid by comparison. The main benefit of Manifold is, as a whole, the project provides far more capabilities than Lombok.

Remember to check out the code examples and resources on my GitHub page to further deepen your understanding of Manifold's property support.

Java (programming language) Debug (command)

Published at DZone with permission of Shai Almog, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Enhancing Java Application Logging: A Comprehensive Guide
  • Effective Tips for Debugging Complex Code in Java
  • Techniques You Should Know as a Kafka Streams Developer
  • How to Configure, Customize, and Use Ballerina Logs

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!