A Java annotation processor for generating algebraic data types with value semantics, pattern matching, and customizable APIs.
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.
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.
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.
adt4j - Algebraic Data Types for Java
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports recursive definitions without special handling, enabling easy creation of complex structures like expression trees, as shown in the Expression example.
Automatically generates hashCode, equals, and toString with value semantics, reducing boilerplate and ensuring consistency in data comparisons.
Allows custom names and access levels for generated methods like predicates and getters, providing flexibility in API design, as per the @Getter annotations.
Implements type-safe pattern matching through visitors, enabling clear and safe operations on data variants, demonstrated in the eval() method example.
Known issues with maven-compiler-plugin version 3.2+ cause duplicate class errors on repeated compilations, requiring clean builds and disrupting development workflow.
Requires a hack (selfReferenceVariableName) for recursive types with generics due to a javac bug, making definitions less elegant and potentially error-prone.
Dependency on annotation processing complicates build setup and can increase compilation time, especially in large projects or with frequent changes.