Describe the feature
When I use the @Value annotation with staticConstructor = "of" and a private Constructor is already defined, Lombok should use the private Constructor to generate a static of Constructor.
Lomboked version
@Value(staticConstructor = "of")
public final class SampleDocument {
private final String value;
private SampleDocument(final String value) {
assertThat(value).isNotEmpty();
this.value = value;
}
}
Java version
public final class SampleDocument {
private final String value;
private SampleDocument(final String value) {
assertThat(value).isNotEmpty();
this.value = value;
}
public static SampleDocument of(final String value) {
return new SampleDocument(value);
}
[...]
}
Describe the target audience
Every programer who want's to do DDD and validate its value objects in the constructor to have only valid domain objects.
Additional context
Currently when a private constructor is already defined no static of constructor will be generated at all.
I understand the request, and think it is a good idea to generate the static method if staticConstructor is provided, even if we don't generate the (private) all-args constructor.
If someone would create a pull request with implementations for ecj and javac and create test files in our test infrastructure, this gets higher priority.
Liked the idea and have have a pull request up for this here https://github.com/rzwitserloot/lombok/pull/2119
It's fixed. We just need to add it to the changelog.
Most helpful comment
Liked the idea and have have a pull request up for this here https://github.com/rzwitserloot/lombok/pull/2119