's equals, hashCode, and toString methods are overridden and fully dependent on attribute values Immutable implementation classĪ Generated final class that extends a manually-written abstract value typeĪnd implements all declared accessor methods as well as supporting fields, methods, constructors, and a builder class.Īn immutable implementation class implements abstract attribute accessorsįor scalar primitive and object reference types, with special support provided for collection attributes Such accessors therefore require special annotations to distinguish them from regular methods. However, some attributesĪre non- abstract methods that have bodies that compute values. No annotations are required on abstract accessor methods in order for them to become attributes. It is defined by an accessor method: A zero argument, non- void-returning Java method. The name "attribute" is used to intentionally distinguish the concept from "fields" or JavaBean "properties", and to imply a similarity with Java annotation attributes. Get started!.Īn attribute holds a value that cannot be changed after the owning object is created. It is strongly recommended that abstract value types not introduce visible mutable state.Ībstract value types are used as the source model for generated code. It may contain attributes and other metadata, as well as regular Java methods (and fields, if necessary). Interface (or even annotation type) that defines the value type and is annotated with the Or jump straight to the features! ConceptsĪn Abstract value type is a manually-written non-final (usually abstract) class or
#Model builder precondition code#
See sample generated code for an example of the code generated by the processor, Get started! Create an abstract value class and then add annotation to generate an immutable implementation class! No ugly IDE-generated hashCode, equals and toString methods that end up being stored in source control.Object definitions are pleasant to write and read.Immutable objects are naturally thread-safe and can therefore be safely shared among threads.Cannot be sneakily modified when passed to other code.Will fail if mandatory attributes are missing.
Immutable objects are constructed once, in a consistent state, and can be safely shared.
We feel proud to fill a gap in the area of modelling in the Java programming language, where conventional JavaBeans are insufficient. Good modelling is at the heart of creating good applications and Guava's Immutable Collections but for regular objects. To easily create simple and consistent value objects. To reap the benefits of immutability in Java, we created an annotation processor