Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Java
  3. ADT4J

ADT4J

BSD-3-ClauseJavaadt4j-2.0.1

A Java annotation processor for generating algebraic data types with value semantics, pattern matching, and customizable APIs.

GitHubGitHub
150 stars9 forks0 contributors

What is ADT4J?

ADT4J is a Java library that implements algebraic data types (ADTs) through an annotation processor. It generates boilerplate code for custom data types, enabling pattern matching, value semantics, and recursive definitions in Java. The project solves the problem of verbose and error-prone manual implementation of ADTs in a language lacking native support.

Target Audience

Java developers working on projects that benefit from algebraic data types, such as compilers, interpreters, or complex domain models, and those seeking type-safe pattern matching without switching languages.

Value Proposition

Developers choose ADT4J for its ability to bring functional programming constructs to Java with minimal boilerplate, customizable generated code, and compatibility with existing Java tooling and inheritance.

Overview

adt4j - Algebraic Data Types for Java

Use Cases

Best For

  • Implementing expression trees or abstract syntax trees in Java
  • Reducing boilerplate in domain models with complex data shapes
  • Adding type-safe pattern matching to Java applications
  • Creating recursive data structures with automatic value semantics
  • Generating serializable and comparable implementations for custom types
  • Experimenting with algebraic data types in a Java ecosystem

Not Ideal For

  • Projects relying on Maven 3.2+ for incremental builds, due to known duplicate class errors that require clean compilations
  • Applications where compilation speed is critical, as annotation processors can slow down the build process
  • Teams that prefer to maintain all code manually without generation, for better control and debugging
  • Simple domain models where standard Java classes suffice and algebraic data types add unnecessary complexity

Pros & Cons

Pros

Recursive Data Support

Supports recursive definitions without special handling, enabling easy creation of complex structures like expression trees, as shown in the Expression example.

Value Semantics Generation

Automatically generates hashCode, equals, and toString with value semantics, reducing boilerplate and ensuring consistency in data comparisons.

Customizable API

Allows custom names and access levels for generated methods like predicates and getters, providing flexibility in API design, as per the @Getter annotations.

Visitor-Based Pattern Matching

Implements type-safe pattern matching through visitors, enabling clear and safe operations on data variants, demonstrated in the eval() method example.

Cons

Build Tool Incompatibilities

Known issues with maven-compiler-plugin version 3.2+ cause duplicate class errors on repeated compilations, requiring clean builds and disrupting development workflow.

Javac Bug Workarounds

Requires a hack (selfReferenceVariableName) for recursive types with generics due to a javac bug, making definitions less elegant and potentially error-prone.

Annotation Processor Overhead

Dependency on annotation processing complicates build setup and can increase compilation time, especially in large projects or with frequent changes.

Frequently Asked Questions

Quick Stats

Stars150
Forks9
Contributors0
Open Issues12
Last commit8 years ago
CreatedSince 2014

Tags

#annotation-processor#algebraic-data-types#type-safety#java#pattern-matching#visitor-pattern#code-generation

Built With

M
Maven
J
Java

Included in

Java47.5k
Auto-fetched 9 hours ago

Related Projects

JHipsterJHipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.

Stars22,447
Forks4,189
Last commit10 hours ago
JavaPoetJavaPoet

A Java API for generating .java source files.

Stars10,847
Forks1,395
Last commit1 year ago
autoauto

A collection of source code generators for Java.

Stars10,555
Forks1,224
Last commit3 days ago
Record-BuilderRecord-Builder

Record builder generator for Java records

Stars929
Forks69
Last commit1 month ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub